validat-6ren">
gpt4 book ai didi

php - 如何解决 "SQLSTATE[42S22]: Column not found"?

转载 作者:太空宇宙 更新时间:2023-11-03 11:24:33 26 4
gpt4 key购买 nike

我将我的“id”重命名为“teams_id”

Look at the picture

现在当我更新时它显示以下错误

Look at the image

我也尝试在我的模型中使用 declare it 但它不起作用

enter image description here

这是我的更新代码:

{
$this->validate(request(), [
'coach' => 'required',
'team' => "required|unique:teams,team,$id",
'manager' => "required|unique:teams,manager,$id",
]);

$team=Team::findorfail($id);

$team->team = $request->input('team');
$team->coach = $request->input('coach');
$team->manager = $request->input('manager');

$team->save();
Toastr::success('Team info was updated','Success!');
return redirect('/teams');

}

最佳答案

验证失败。 The unique validation rule正在检查 id 列。它不使用模型主键。相反,将您的验证规则更改为以下内容:

    $this->validate(request(), [
'coach' => 'required',
'team' => "required|unique:teams,team,$id,teams_id",
'manager' => "required|unique:teams,manager,$id",
]);

关于php - 如何解决 "SQLSTATE[42S22]: Column not found"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55593338/

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