SQLSTATE [42S22]:未找到列:1054未知列'命名'在' where子句'

时间:2017-07-08 04:44:41

标签: php mysql laravel-5

我有一些代码产生以下错误。我该如何解决?

 "SQLSTATE[42S22]: Column not found: 1054 Unknown column ' name' in 'where clause' (SQL: select count(*) as aggregate from `authors` where ` name` = Azzario Razy Junaidi and `id` <> 4)"
AuthorsController.php
public function update(Request $request, $id)
{
    $this->validate($request, ['name' => 'required|unique:authors, name,'.$id]);
    $author = Author::find($id);
    $author->update($request->only('name'));
    Session::flash("flash_notification", [
      "level" => "success",
      "message" => "Berhasil menyimpan $author->name"
    ]);
    return redirect()->route('authors.edit');
}

2 个答案:

答案 0 :(得分:1)

听起来像你的数据库缺少authors表上的name列。

“SQLSTATE [42S22]:未找到列:1054 'where子句'中的未知列'name'(SQL:选择count(*)作为聚合来自作者其中name = Azzario Razy Junaidi和id&lt;&gt; 4)

答案 1 :(得分:0)

您必须在此处的AuthorsController.php中的(名称)中删除空格:

'name' => 'required|unique:authors, name,'

然后输入:

'name' => 'required|unique:authors,name,'

它将起作用?