Laravel redirect with logout not working
Solution 1
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
Solution 2
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');
});
}
Solution 3
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;
Solution 4
Due to the current Laravel update there should be a "remember_token" column in the user table. This solves the problem.
Solution 5
here is a sample code from how I handle logging out users on my system using Laravel 4. I am not sure why yours isn't working and it will be great to see your route, and html code that triggers the logout process as well.
The Route
Route::get('logout', array('uses'=>'UserController@logout'));
The HTML button/link triggering the logout
<a href="{{URL::to('logout')}}" class="btn btn-danger btn-sm">Logout</a>
The Controller Function Handling the logout
public function logout(){
Auth::logout();
return Redirect::to('login');
}
Here you got! You should replace it with your route names and controller function. This should work! If it doesn't, post your route and html code! Cheers!
Related videos on Youtube
winnyboy5
Hello, I am Web Programmer and designer from India, who is obsessed with programming and designing.
Updated on October 25, 2020Comments
-
winnyboy5 over 3 years
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)
-
toesslab about 10 yearsCan you show the route? Does the
users.login
view exist? Because your code looks pretty the same as my logout method... -
Quasdunk about 10 yearsIn order to get useful debug information displayed on your developing machine, you should add a
'debug' => true'
toapp/config/app.php'
(orapp/config/local/app.php'
) and/or add your dev machine's hostname to the environments-array inbootstrap/start.php
. Have a look at laravel.com/docs/configuration#environment-configuration for more details. -
winnyboy5 about 10 years@pc-shooter yes that view exists. the redirect works fine without Auth::logout()
-
toesslab about 10 yearshave a look at Quasdunk's comment
-
winnyboy5 about 10 years@Quasdunk tried it throws some sql exception. don't know why.....
-
winnyboy5 about 10 years@Quasdunk thanks for the suggestion. It helped me alot
-
Quasdunk about 10 years@winnyboy5 Always glad to help :) Also make sure to disable any sort of direct debugging output (you should log it instead) for your production environment, so your users only see the 'Whoops, looks like something went wrong' message instead of some sensitive data.
-
winnyboy5 about 10 years@Quasdunk sure thanks for the tip too. :)
-
-
winnyboy5 about 10 yearsNope it didn't work. I think the issue lies in the getLogout function
-
mandeeya about 10 yearsGreat! Glad you fixed it! Cheers!
-
Alexander Kim almost 10 yearsIf being more in detail - you have to edit your migrations file and add: $table->text('remember_token')->nullable(); and then rerun migrations
-
Tom Busby over 9 yearsCan this be done in an automatic way like with the timestamps? ($table->timestamps();)
-
lagbox over 9 years@TomBusby actually the docs for Laravel 4.2 have a method for this token now. $table->rememberToken();
-
Merlin -they-them- over 9 yearsHad this problem previously. The docs do not make it clear that this method is for 4.2 and up. I was trying to use it on 4.1.26
-
Resul Rzaeeff about 6 years"migrate:make" is wrong we need type "make:migration". Thank you for answer.