我的顶部导航栏中有一个"注销"链接.我想知道怎样才能在我登录时,当我点击它并返回主页时,它会将我注销.
To be specific, what changes to which files do I make in Laravel? Also, what code do I need to write in the view, which currently contains just HTML, to trigger this?
我的顶部导航栏中有一个"注销"链接.我想知道怎样才能在我登录时,当我点击它并返回主页时,它会将我注销.
To be specific, what changes to which files do I make in Laravel? Also, what code do I need to write in the view, which currently contains just HTML, to trigger this?
Edited 28/12/2019: It's work, but This answer contains a serious security issue. Please consider before using it. The Answer by Lucas Bustamante
maybe a better choice. Refer to the comment section of this answer.
1) if you are using the auth scaffold that laravel contains. You can do this, in your navigation bar add this:
<a href="{{ url('/logout') }}"> logout </a>
然后将其添加到您的web.php文件中
Route::get('/logout', '\App\Http\Controllers\Auth\LoginController@logout');
Done. This will logout you out and redirect to homepage. To get the auth scaffold, from command line, cd into your project root directory and run
php artisan make:auth
2) add this to your navigation bar:
<a href="{{ url('/logout') }}"> logout </a>
then add this in your web.php file
Route::get('/logout', 'YourController@logout');
然后在YourController.php文件中添加以下内容
public function logout () {
//logout user
auth()->logout();
// redirect to homepage
return redirect('/');
}
Done.
阅读:
https://mattstauffer.co/blog/the-auth-scaffold-in-laravel-5-2
https://www.cloudways.com/blog/laravel-login-authentication/