laravel中不使用 remember_token时退出报错,如何解决?

laravel中不使用 remember_token时退出报错,如何解决?

在laravel5.5中,如果不使用remember_token登陆,那么,在退出登陆状态时会报错,比如下面是本人程序的报错,

Illuminate \ Database \ QueryException (42S22)

SQLSTATE[42S22]: Column not found: 1054 Unknown column'remember_token' in 'field list' (SQL: update `admin_users` set`remember_token` = OuB1UKZeDasyHUXQCZZ0iMSzKzYUejypth3G35pCgL6WanIAxsYFwQ5p5xH3where `id` = 1)

解决问题的办法也很简单,这个remember_token 是定义在

D:\wamp64\www\laravel\larablog\vendor\laravel\framework\src\Illuminate\Auth\Authenticatable.php

protected $rememberTokenName = 'remember_token';

在你创建的模型中(我这里是User),改写掉这个rememeber_token,返回后程序不会再去数据库中找这一条了。如下,

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    ...
    //加上下面这一句,相当于把$rememberTokenName清空,
    protected $rememberTokenName = '';
    ....
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    // protected $hidden = [
    //     'password', 'remember_token',
    // ];
    protected $hidden = [
        'password',
    ];
}
posted @ 2017-12-15 20:58  SpaceVision  阅读(23)  评论(0编辑  收藏  举报