Using POST vs. GET to log out
Last active
September 5, 2017 15:20
-
-
Save kirkaracha/f7ddbcefd0bcaf370ea6 to your computer and use it in GitHub Desktop.
Laravel 5.1 POST to Log Out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// partial in app/resources/views/auth | |
// uses Laravel Collective Forms & HTML package | |
// http://laravelcollective.com/docs/5.1/html | |
{!! Form::open([ | |
'route' => 'logout.post', | |
'name' => 'logout-form', | |
'id' => 'logout-form', | |
]) !!} | |
{!! Form::button('Log Out', [ | |
'type' => 'submit' | |
]) !!} | |
{!! Form::close() !!} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// partial in app/resources/views/auth | |
// alternate Blade version without package dependency | |
<form method="POST" action="{{ route('logout.post') }}" accept-charset="UTF-8" name="logout-form" id="logout-form"> | |
{{ csrf_field() }} | |
<button type="submit">Log Out</button> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// add to app/Http/Auth/AuthController.php | |
/** | |
* Handle a logout request to the application. | |
* | |
* @return \Illuminate\Http\Response | |
*/ | |
public function postLogout() | |
{ | |
Auth::logout(); | |
return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// add to app/Http/routes.php | |
Route::post('/logout', [ | |
'as' => 'logout.post', | |
'uses' => 'Auth\AuthController@postLogout', | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment