Add Reinink\RememberQueryStrings dependency

This commit is contained in:
Jonathan Reinink 2019-04-02 13:43:01 -04:00
parent 584210a182
commit bfcee13af9
5 changed files with 44 additions and 59 deletions

View File

@ -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,
];

View File

@ -1,56 +0,0 @@
<?php
namespace App\Http\Middleware;
use Closure;
class RememberQueryStrings
{
public function handle($request, Closure $next)
{
if ($request->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()));
}
}

View File

@ -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": {

42
composer.lock generated
View File

@ -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",

View File

@ -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');