Skip to content

Instantly share code, notes, and snippets.

@kirkaracha
Last active September 5, 2017 15:20
Show Gist options
  • Save kirkaracha/f7ddbcefd0bcaf370ea6 to your computer and use it in GitHub Desktop.
Save kirkaracha/f7ddbcefd0bcaf370ea6 to your computer and use it in GitHub Desktop.
Laravel 5.1 POST to Log Out
<?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() !!}
<?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>
<?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 : '/');
}
<?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