To manually log users out of your application, you may use the logout
method on the Auth
facade. This will clear the authentication information in the user's session:
use Illuminate\Support\Facades\Auth;
Auth::logout();
1) if you are using the auth scaffold that laravel contains. You can do this, in your navigation bar add this:
Implement below code in web.php file
<a href="{{ url('/logout') }}"> logout </a>
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
Example(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');
then in the YourController.php file, add this
public function logout () {
//logout user
auth()->logout();
// redirect to homepage
return redirect('/');
}