reinink / remember-query-strings by reinink

Laravel middleware that automatically remembers and restores query strings.
378,070
75
4
Package Data
Maintainer Username: reinink
Maintainer Contact: jonathan@reinink.ca (Jonathan Reinink)
Package Create Date: 2019-04-02
Package Last Update: 2023-07-10
Language: PHP
License: MIT
Last Refreshed: 2024-11-17 03:07:56
Package Statistics
Total Downloads: 378,070
Monthly Downloads: 9,201
Daily Downloads: 64
Total Stars: 75
Total Watchers: 4
Total Forks: 8
Total Open Issues: 2

Remember Query Strings

Remember Query Strings is a Laravel middleware that automatically remembers and restores query strings. It does this by remembering the last query strings visited in the session. Later, when you visit that same route, if no query strings are provided, the middleware will automatically restore them from the sessions via a redirect.

Installation

You can install this package via Composer:

composer require reinink/remember-query-strings

Setup

First register the route middleware in your App\HttpKernel class:

protected $routeMiddleware = [
    // ..
    'remember' => \Reinink\RememberQueryStrings::class,
];

Usage

Now you can use this middleware just like any other middleware. For example, in your routes:

Route::get('users')->name('users')->uses('UsersController@index')->middleware('remember');

Or in a controller:

class UserController extends Controller
{
    public function __construct()
    {
        $this->middleware('remember')->only('index');
    }
}

Opting out

If you'd like to visit a page without remembering the query strings, pass ?remember=no to disable this behviour for that visit.

Forgetting query strings

To forget previously remembered query strings, simply pass ?remember=forget.