php Laravel 重定向与注销不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23242533/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:36:35  来源:igfitidea点击:

Laravel redirect with logout not working

phpauthenticationredirectlaravellaravel-4

提问by winnyboy5

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.

我正在使用 laravel 4 框架。当我在 Auth::logout() 之后使用重定向时,重定向不起作用。我也使用了 View::make(),但同样的“哎呀,好像出了点问题。” 错误抛出。

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

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) 

回答by lagbox

You may be missing the remember_token for the users table.

您可能缺少用户表的 remember_token。

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

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

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

Laravel 需要“可空的 remember_token of VARCHAR(100)、TEXT 或等效于您的用户表。”

Update for new documentation

更新新文档

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

Laravel 4.2 及更高版本现在有一种方法可以与架构构建器一起使用来添加此列。

$table->rememberToken();

$table->rememberToken();

Laravel Docs - Schema - Adding Columns

Laravel 文档 - 架构 - 添加列

回答by paulalexandru

If you have Laravel 4.2 you can do this:

如果你有 Laravel 4.2 你可以这样做:

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:

在此之后打开文件 app/database/migrations/2014_10_16_124421_add_remember_token_to_users_table 并像这样编辑它:

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

public function down()
{
    Schema::table('users', function(Blueprint $table)
    {
        $table->dropColumn('remember_token');
    });
}

回答by raju poudel

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

对于您的问题,您可能会传递空值,或者您可能会在模型 php 文件中关闭您的 remember_token 值作为

public $remember_token=false;

回答by mandeeya

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.

这是我如何使用 Laravel 4 在我的系统上处理注销用户的示例代码。我不确定为什么你的不工作,很高兴看到你的路线,以及触发注销过程的 html 代码。

The Route

路线

Route::get('logout', array('uses'=>'UserController@logout'));

The HTML button/link triggering the logout

触发注销的 HTML 按钮/链接

<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!

给你!您应该将其替换为您的路由名称和控制器功能。这应该有效!如果没有,请发布您的路线和 html 代码!干杯!

回答by Bastin Robin

Due to the current Laravel update there should be a "remember_token"column in the user table. This solves the problem.

由于当前的 Laravel 更新,用户表中应该有一个“remember_token”列。这解决了问题。

回答by Eenvincible

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.

这很顺利。

回答by palash3593

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.

您需要将 updated_at 列添加到 SQL 表 user_tbl 中。如果您不想使用它。您还可以关闭模​​型中的时间戳。