In this tutorial we’re going to learn how to create logout function in laravel i have mentioned in every easy steps how and where to implement functions.
1st step go to web.php
Route::get('/user/logout', [BrandController::class, 'Logout'])->name('user.logout')->name('user.logout');
Next go to your controller and paste below code
public function Logout(Request $request)
{
auth('web')->logout();
return redirect()->route('login')->with('logout', 'Logged out successfully');
}
Next go to view page and put this code
<a href="{{ route('user.logout')}}"> <i class="mdi mdi-logout"></i> Log Out </a>
public function Logout(Request $request)
{
if (auth('web')->check()) {
auth('web')->logout();
$message = 'Logged out successfully';
} else {
$message = 'You are already logged out';
}
return redirect()->route('login')->with('logout', $message);
}
Got to blade page and put this
<a class="dropdown-item" href="{{ route('admin.logout') }}"><i class='bx bx-log-out-circle'></i><span>Logout</span></a>
Now logout working successfully.