如果涉及auth中间件,闪存数据的重定向是否会持续存在?
需要注意的一些内务处理事项将回答一些可能的后续问题:
$request->session()->reflash();
因此,Authenticate.php现在显示如下:
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->guest()) {
if ($request->ajax() || $request->wantsJson()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('login');
}
}
$request->session()->reflash();
return $next($request);
}
此问题也影响make:auth生成的auth样板文件,导致$ errors无法显示错误。
更新(美国东部时间3/29 @ 08:54)
我发现了我认为是根本原因,正如您将在下面看到的那样。每条路线都在呼叫网络'中间件两次。因此,实际上发生了两个请求,即在用户有机会看到它们之前删除了flash消息。原始路线:列表如下。
+--------+----------+-------------------------+------+-----------------------------------------------------------------+---------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-------------------------+------+-----------------------------------------------------------------+---------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | groups | | App\Http\Controllers\GroupsController@index | web,web,auth |
| | GET|HEAD | groups/set-default/{id} | | App\Http\Controllers\GroupsController@setDefaultGroup | web,web,auth |
| | GET|HEAD | home | | App\Http\Controllers\HomeController@index | web,web,auth |
| | GET|HEAD | login | | App\Http\Controllers\Auth\AuthController@showLoginForm | web,web,guest |
| | POST | login | | App\Http\Controllers\Auth\AuthController@login | web,web,guest |
| | GET|HEAD | logout | | App\Http\Controllers\Auth\AuthController@logout | web,web |
| | POST | password/email | | App\Http\Controllers\Auth\PasswordController@sendResetLinkEmail | web,web,guest |
| | POST | password/reset | | App\Http\Controllers\Auth\PasswordController@reset | web,web,guest |
| | GET|HEAD | password/reset/{token?} | | App\Http\Controllers\Auth\PasswordController@showResetForm | web,web,guest |
| | GET|HEAD | register | | App\Http\Controllers\Auth\AuthController@showRegistrationForm | web,web,guest |
| | POST | register | | App\Http\Controllers\Auth\AuthController@register | web,web,guest |
| | GET|HEAD | visitees | | App\Http\Controllers\VisiteesController@index | web,web,auth |
| | GET|HEAD | visitees/check-in/{id} | | App\Http\Controllers\VisiteesController@checkIn | web,web,auth |
+--------+----------+-------------------------+------+-----------------------------------------------------------------+---------------+
从“网络”中删除路线后,我的路线现在显示如下中间件:
+--------+----------+-------------------------+------+-----------------------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-------------------------+------+-----------------------------------------------------------------+------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | groups | | App\Http\Controllers\GroupsController@index | web,auth |
| | GET|HEAD | groups/set-default/{id} | | App\Http\Controllers\GroupsController@setDefaultGroup | web,auth |
| | GET|HEAD | home | | App\Http\Controllers\HomeController@index | web,auth |
| | GET|HEAD | login | | App\Http\Controllers\Auth\AuthController@showLoginForm | web,guest |
| | POST | login | | App\Http\Controllers\Auth\AuthController@login | web,guest |
| | GET|HEAD | logout | | App\Http\Controllers\Auth\AuthController@logout | web |
| | POST | password/email | | App\Http\Controllers\Auth\PasswordController@sendResetLinkEmail | web,guest |
| | POST | password/reset | | App\Http\Controllers\Auth\PasswordController@reset | web,guest |
| | GET|HEAD | password/reset/{token?} | | App\Http\Controllers\Auth\PasswordController@showResetForm | web,guest |
| | GET|HEAD | register | | App\Http\Controllers\Auth\AuthController@showRegistrationForm | web,guest |
| | POST | register | | App\Http\Controllers\Auth\AuthController@register | web,guest |
| | GET|HEAD | visitees | | App\Http\Controllers\VisiteesController@index | web,auth |
| | GET|HEAD | visitees/check-in/{id} | | App\Http\Controllers\VisiteesController@checkIn | web,auth |
+--------+----------+-------------------------+------+-----------------------------------------------------------------+------------+
将路线移出'网络'中间件组,flash消息显示正确。 但是,现在我有了一个新问题!
初始请求后,不会从会话中删除Flash消息。它们会持续存储每个后续请求,直到手动刷新或忘记它们为止。
我现在还不确定是否应该打开另一个专门解决闪存数据持续存在问题的问题。如果是的话请告知。
答案 0 :(得分:0)
请运行composer update
将laravel / framework更新为v5.2.27,然后发出php artisan make:auth
以重新生成auth路由