我需要将错误传递给路由,然后通过重定向将其传递给另一条路由。
在异常处理程序中,我有:
public function render($request, Exception $e)
{
return redirect('/')
->withErrors(['my-message-error']);
//return parent::render($request, $e);
}
在routes.php文件中,我有:
Route::get('/', function () {
if (Auth::check()) {
// Here I need to get errors to pass to the "to-do-list"
return redirect('to-do-list')->withErrors(WHAT?);
} else {
return view('auth.login');
}
});
我想将所有错误重定向到基本URL,并且在路由中我可以切换用户而不会丢失消息。
已更新
我找到了解决方案。我可以通过这种方式“刷新”错误消息。
在routes.php文件中,我使用:
Session::reflash();
return redirect('to-do-list');
“刷新”功能不起作用,此代码实际上起作用:
return redirect('to-do-list')->withErrors(Session::get('errors')->default);