There are 2 ways to logout from laravel.
1st way
Routing.
Route::get('/logout', 'Auth\LoginController@logout');
Blade file.
<?php if(Auth::check()){ ?>
<a href="{{ url('/logout') }}">Logout</a>
<?php } ?>
2nd way
Routing.
Route::post('logout','auth\LoginController@getLogout');
Controller.
public function getLogout()
{
$this->auth->logout();
return redirect('/login');
}
Blade file.
<?php if(Auth::check()){ ?>
<a href="{{ url('/logout') }}" class="btn-primary" style="padding:10px;" onclick="event.preventDefault();document.getElementById('logout-form').submit();"> Logout </a>
<form id="logout-form" action="{{ url('/logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}</form>
<?php } ?>
1st way
Routing.
Route::get('/logout', 'Auth\LoginController@logout');
Blade file.
<?php if(Auth::check()){ ?>
<a href="{{ url('/logout') }}">Logout</a>
<?php } ?>
2nd way
Routing.
Route::post('logout','auth\LoginController@getLogout');
Controller.
public function getLogout()
{
$this->auth->logout();
return redirect('/login');
}
Blade file.
<?php if(Auth::check()){ ?>
<a href="{{ url('/logout') }}" class="btn-primary" style="padding:10px;" onclick="event.preventDefault();document.getElementById('logout-form').submit();"> Logout </a>
<form id="logout-form" action="{{ url('/logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}</form>
<?php } ?>
No comments:
Post a Comment