SQLSTATE[42S22]: Column not found: 1054 Unknown column ' name' in 'where clause'

Viewed 13812

I have some code producing the following error. How can I fix it?

 "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 Answers

You have to remove space from ( name) in your AuthorsController.php here:

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

And type this:

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

and it will work

Related