Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) 
like image 467
winnyboy5 Avatar asked Apr 23 '14 11:04

winnyboy5


3 Answers

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

like image 116
lagbox Avatar answered Oct 27 '22 11:10

lagbox


If you have Laravel 4.2 you can do this:

Command Line:

php artisan migrate:make add_remember_token_to_users_table --table="users"

After this open the file app/database/migrations/2014_10_16_124421_add_remember_token_to_users_table and edit it like this:

public function up()
{
    Schema::table('users', function(Blueprint $table)
    {
        $table->rememberToken();
    });
}

public function down()
{
    Schema::table('users', function(Blueprint $table)
    {
        $table->dropColumn('remember_token');
    });
}
like image 45
paulalexandru Avatar answered Oct 27 '22 11:10

paulalexandru


for your problem ,you may pass null value or you may off your remember_token value in your model php file as

public $remember_token=false;
like image 22
raju poudel Avatar answered Oct 27 '22 09:10

raju poudel