winnyboy5 winnyboy5 - 3 months ago 19
PHP Question

Laravel redirect with logout not working

I am Using laravel 4 framework's. When I used redirect after the Auth::logout(), the redirection was not working. I used View::make() too, but same "Whoops, looks like something went wrong." error throws up.

public function getLogout() {
Auth::logout();
return Redirect::to('users/login')->with('message', 'Your are now logged out!');
}


This is the logout code. I am using. Some one please help me with this.

routes.php

Route::get('/', function()
{
return View::make('hello');
});

Route::controller('users', 'UsersController');


HTML

@if(!Auth::check())
<li>{{ HTML::link('users/register', 'Register') }}</li>
<li>{{ HTML::link('users/login', 'Login') }}</li>
@else
<li>{{ HTML::link('users/logout', 'logout') }}</li>
@endif


This is what my debugger shows.

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'remember_token' in 'field list' (SQL: update `users` set `updated_at` = 2014-04-23 11:30:41, `remember_token` = jSMcfpPnCPrKgwqfhB2tEEEd8h8x6d72viz67MbVzBD27A2G7AH8yWQo1ORf where `id` = 1)

Answer

You may be missing the remember_token for the users table.

see: http://laravel.com/docs/upgrade#upgrade-4.1.26

Laravel requires "nullable remember_token of VARCHAR(100), TEXT, or equivalent to your users table."

Update for new documentation

Laravel 4.2 and up now has a method you can use with your schema builder to add this column.

$table->rememberToken();

Laravel Docs - Schema - Adding Columns