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

php - 如何解决“SQLSTATE [42S22]:找不到列”?-LMLPHP

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

php - 如何解决“SQLSTATE [42S22]:找不到列”?-LMLPHP

我也尝试在模型中使用声明它,但是它不起作用

php - 如何解决“SQLSTATE [42S22]:找不到列”?-LMLPHP

这是我的更新代码:

{
     $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');

}

最佳答案

错误可能在您的验证器上

'team' => "required|unique:teams,team,$id",


检查laravel documentation并尝试使用

'team' => "required|unique:teams,team,$id,teams_id",

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

10-15 21:17
查看更多