2
votes

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
Which framwork are u using..?? - Dharmendra Singh
Laravel Framework - Azzario Razy
There should be quotes around the name as> name = 'Azzario Razy Junaidi' and id <> 4 - MJ Khan
Pay closer attention to the error. Unknown column ' name'. Why do you think this says ' name' instead of 'name'? This is a typo, possibly here: 'required|unique:authors, name,' but possibly elsewhere, not shown. The database is complaining that there is no column called [space]name. There should not be a space before name. - Michael - sqlbot

2 Answers

2
votes

Sounds to me like your database is missing the name column on the authors table.

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

0
votes

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 👍