gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 00:57:39 33 4
gpt4 key购买 nike

随着 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/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com