gpt4 book ai didi

php - 在 Laravel 3 中,带有自定义表的模型不会保存

转载 作者:行者123 更新时间:2023-11-30 22:45:21 25 4
gpt4 key购买 nike

我有一个 Eloquent 模型,它使用来自用户表的自定义表。

像这样...

class Appointment extends Eloquent
{
public static $table = null;
public function __construct()
{
parent::__construct();

// Here I load the custom table, from the user table
// Pull the prefix of the table, and append
// This works perfectly fine for viewing the data
static::$table = Auth::user()->tenantTable()."_appointments";
}

public static $connection = 'tenant-data';
public static $timestamps = true;

我可以使用此设置完美地提取和查看数据。所以每个用户,都有自己的预约表。

但是,如果我更改任何内容然后使用 Eloquent save() 方法。我收到一个永不结束的递归调用。

我需要在 laravels save() 方法中更改什么才能让它工作?

我必须在核心中更改它吗?或者我可以覆盖当前模型中的 save() 方法吗?如果是这样,怎么做到的?

最佳答案

我几乎只是猜测,但您是否尝试更改构造函数命令的顺序?先动态设置表再调用父构造函数?

关于php - 在 Laravel 3 中,带有自定义表的模型不会保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29810511/

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