gpt4 book ai didi

php - Laravel - 重命名表后 - 调用未定义的方法 updateOrCreate()

转载 作者:行者123 更新时间:2023-11-29 10:50:50 28 4
gpt4 key购买 nike

在必须重命名数据库表并运行迁移后,我得到:

SQLSTATE[42S02]: Base table or view not found

对于这段代码:

  Shop::updateOrCreate(
['id' => $id],
['title' => $shopeTitle]
);

Mall::where('id', $id)->update([
'price' => $price,
'visitors' => $visitors
]);

if ($mall != 41 || $mall!= 42) {
DB::table('calc_stores_in_malls')->insert([
'mall' => $price,
'store' => $id
]);
}

然后我尝试对新表名称进行硬编码,如下所示:

     DB::table('calc_shop')->updateOrCreate(
['id' => $id],
['title' => $shopeTitle]
);

DB::table('calc_stores_in_malls')->where('id', $id)->update([
'price' => $price,
'visitors' => $visitors
]);

if ($mall != 41 || $mall!= 42) {
DB::table('calc_stores_in_malls')->insert([
'mall' => $price,
'store' => $id
]);
}

但是后来我得到了新的错误:

Call to undefined method Illuminate\Database\Query\Builder::updateOrCreate()

我该如何解决这个问题?

最佳答案

updateOrCreate 是一个 Eloquent 函数。

最简单的方法是通过执行以下操作来浏览模型并更新表名称:

$protected $table = 'new_table_name';

关于php - Laravel - 重命名表后 - 调用未定义的方法 updateOrCreate(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43762039/

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