问题
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)
回答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
回答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');
});
}
回答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;
回答4:
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!
回答5:
Due to the current Laravel update there should be a "remember_token" column in the user table. This solves the problem.
回答6:
I learned that I was getting the logout error in my application because I was using
Route::post('logout', array('uses' => 'SessionController@doLogout'));
Just remember to use the following instead.
Route::get('logout', array('uses' => 'SessionController@doLogout'));
This worked smoothly.
回答7:
You need to add updated_at column into your SQL table user_tbl. If you do not wish to use it. you may also turn off timestamps within your model.
来源:https://stackoverflow.com/questions/23242533/laravel-redirect-with-logout-not-working