laravel - 使用 Laravel 是否可以使用外部用户数据库绕过对 Remember_token 的需求

标签 laravel laravel-4

随着 Laravel 最近的更新,它们需要一个 Remember_token 和 Updated_at。

登录和退出时我得到:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'remember_token' in 'field list' (SQL: update `account` set `remember_token` = s8XPDCdNdJnjbLj7MlDRO1Cy5owwjxdfW1rYVhd6QpePIltqPkavr9l3KUbd, `updated_at` = 2014-07-30 14:09:37 where `id` = 5)

我正在使用外部用户数据库,我不想在该数据库上创建这些额外的字段,因为它也在我不想弄乱的游戏服务器上使用。

有没有办法绕过对这两列的需要?

最佳答案

我非常确定使用 Laravel 内置的 Auth 系统(Guard)会让您使用 UserInterface,而 UserInterface 又会让您定义这些。但是,您可以通过使用这些方法来伪造它,但让它们返回无用的信息。

<?php

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface
{
    use UserTrait, RemindableTrait;

    protected $hidden = array('password', 'remember_token');
    public $timestamps = false;

    public function getRememberToken()
    {
        return '';
    }

    public function setRememberToken($value)
    {
    }

    public function getRememberTokenName()
    {
        // just anything that's not actually on the model
        return 'trash_attribute';
    }

    /**
     * Fake attribute setter so that Guard doesn't complain about
     * a property not existing that it tries to set.
     *
     * Does nothing, obviously.
     */
    public function setTrashAttributeAttribute($value)
    {
    }
}

这可能只是做你想做的事 - 基本上覆盖这些函数,使其无法正常工作,这意味着 1)你不需要弄乱你的数据库,2)当功能不起作用时,没关系,因为你'无论如何我都没有使用它。


正如 @neeraj 所说,对于 created_at 事情,只需执行 $timestamps = false 并希望得到最好的结果。更新了上面的模型以反射(reflect)这一点。

关于laravel - 使用 Laravel 是否可以使用外部用户数据库绕过对 Remember_token 的需求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25039144/

相关文章:

php - Laravel Eloquent : How can I define this relationship?

laravel - 在 Blade 模板中使用 Vue 组件是最佳实践吗?

php - Laravel redirect()->intended() 在自定义登录 Controller 中不起作用

php - 使用 Eloquent 查找或创建

php - Laravel 搜索关系

javascript - 如何使用 Laravel 发送跨域 Ajax POST

php - 拉拉维尔 8 : Symbolic Link not appearing in public

php - 404 错误 laravel 4 路由

php - 在 Laravel 中递归创建文件夹

php - 在 Laravel 中使用 updateOrCreate 进行多数据插入