app/Http/Controllers/Auth/LogiController.php
在我的应用程序文件夹中,我有一个LoginController,我覆盖了注销功能,添加了一个会话闪存:
public function logout(Request $request)
{
$this->guard()->logout();
$request->session()->flush();
$request->session()->regenerate();
$request->session()->flash('status', 'Task was successful!');
error_log('~~~~~~~~~~~~~~~~~~~~~');
error_log($request->session()->get('status'));
error_log('~~~~~~~~~~~~~~~~~~~~~');
return redirect('/');
}
我的错误日志在这里工作,但当我真正被重定向时,它会转到routes/web.php行:
Route::get('/', 'HomeController@index');
但在这一点上,会议似乎已经不复存在。我的最终目标是在我的登录页面上显示用户已成功注销。我有一种感觉,我的逻辑有缺陷,它正在通过路由文件被删除,但我知道在某个时候,我确实在给会议写信。有什么建议吗?
在我的情况下,我只使用
Session::flash('message','User Just Logout');
Session::flash('alert','alert-danger');
我用这个代码在刀片模板文件上获取我的消息
@if(Session::has('message'))
<p class="alert {{ Session::get('alert-class', 'alert-info') }}">{{ Session::get('message') }}</p>
@endif
我仍然可以使用该功能向我的所有路线发出警报,而不会出现错误
当您注销会话时,会话将过期,因此会话闪存消息不会显示。。。所以你必须在没有会话的情况下使用flash消息。。。使用另一种方法来显示flash消息。
试试这个
public function logout(){
//Illuminate'Support'Facades'Auth::logout();
Auth::logout();
flash()->info('Bye', 'You have been successfully logged out!');
return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
}