From bfcee13af9509b460cb37428528d52542f1beb19 Mon Sep 17 00:00:00 2001 From: Jonathan Reinink Date: Tue, 2 Apr 2019 13:43:01 -0400 Subject: [PATCH] Add Reinink\RememberQueryStrings dependency --- app/Http/Kernel.php | 2 +- app/Http/Middleware/RememberQueryStrings.php | 56 -------------------- composer.json | 1 + composer.lock | 42 ++++++++++++++- routes/web.php | 2 +- 5 files changed, 44 insertions(+), 59 deletions(-) delete mode 100644 app/Http/Middleware/RememberQueryStrings.php diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 9592b81..0587b22 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -59,7 +59,7 @@ class Kernel extends HttpKernel 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, - 'remember' => \App\Http\Middleware\RememberQueryStrings::class, + 'remember' => \Reinink\RememberQueryStrings::class, 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, ]; diff --git a/app/Http/Middleware/RememberQueryStrings.php b/app/Http/Middleware/RememberQueryStrings.php deleted file mode 100644 index ca6f500..0000000 --- a/app/Http/Middleware/RememberQueryStrings.php +++ /dev/null @@ -1,56 +0,0 @@ -wantsJson()) { - return $next($request); - } - - if (empty($request->all())) { - return $this->remembered($next, $request); - } - - if ($request->get('remember') === 'no') { - return $next($request); - } - - if ($request->get('remember') === 'forget') { - return $this->forget($next, $request); - } - - return $this->remember($next, $request); - } - - protected function remembered($next, $request) - { - $remembered = array_filter($request->session()->get('remember_query_strings.'.$request->route()->getName()) ?? []); - - if ($remembered) { - $request->session()->reflash(); - - return redirect(url($request->path()).'?'.http_build_query($remembered)); - } - - return $next($request); - } - - protected function remember($next, $request) - { - $request->session()->put('remember_query_strings.'.$request->route()->getName(), array_filter($request->all())); - - return $next($request); - } - - protected function forget($next, $request) - { - $request->session()->remove('remember_query_strings.'.$request->route()->getName()); - - return redirect(url($request->path())); - } -} diff --git a/composer.json b/composer.json index 5d24687..40b690a 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "laravel/framework": "5.8.*", "laravel/tinker": "^1.0", "openpsa/ranger": "^0.4.0", + "reinink/remember-query-strings": "^0.1.0", "tightenco/ziggy": "^0.6.9" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 5c1e4a6..a3fd90f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1e605df0d49e56e6f5c11bd44dd6c7eb", + "content-hash": "0355694807fea35952ab921c638f6d8b", "packages": [ { "name": "dnoegel/php-xdg-base-dir", @@ -1531,6 +1531,46 @@ ], "time": "2018-07-19T23:38:55+00:00" }, + { + "name": "reinink/remember-query-strings", + "version": "v0.1.0", + "source": { + "type": "git", + "url": "https://github.com/reinink/remember-query-strings.git", + "reference": "91c7723a4545ba96d0474581563b30cd262f56e2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reinink/remember-query-strings/zipball/91c7723a4545ba96d0474581563b30cd262f56e2", + "reference": "91c7723a4545ba96d0474581563b30cd262f56e2", + "shasum": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "Reinink\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jonathan Reinink", + "email": "jonathan@reinink.ca", + "homepage": "https://reinink.ca" + } + ], + "description": "Laravel middleware that automatically remembers and restores query strings.", + "homepage": "https://github.com/reinink/remember-query-strings", + "keywords": [ + "laravel", + "middleware", + "query-strings" + ], + "time": "2019-04-02T17:35:40+00:00" + }, { "name": "swiftmailer/swiftmailer", "version": "v6.2.0", diff --git a/routes/web.php b/routes/web.php index 5f27983..f0ef8c7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -17,7 +17,7 @@ Route::post('login')->name('login.attempt')->uses('Auth\LoginController@login'); Route::get('logout')->name('logout')->uses('Auth\LoginController@logout'); // Dashboard -Route::get('/')->name('dashboard')->uses('DashboardController@index')->middleware('remember', 'auth'); +Route::get('/')->name('dashboard')->uses('DashboardController@index')->middleware('auth'); // Accounts Route::get('accounts')->name('accounts')->uses('AccountsController@index')->middleware('remember', 'auth');