0
Follows the code:
public function update(Request $request, Contact $contact)
{
$validator = Validator::make($request->all(), [
'name' => 'required|min:6|max:255',
'email' => 'required|email|unique:contacts,' . $contact->id
]);
if ($validator->fails()) {
$errors = $validator->errors();
return response()->json($errors, 400);
}
$contact->update($request->all());
return response()->json($contact);
}
Url:
http://127.0.0.1:8000/api/contacts/1
Method:
PUT -> Body -> x-www-form-urlencoded
Error:
Illuminate Database Queryexception: SQLSTATE[42703]: Undefined column: 7 ERROR: column "1" does not exist LINE 1: select Count() as Aggregate from "Contacts" Where "1" = $1 (SQL: select Count() as Aggregate from "Contacts" Where "1" = [email protected]) in file C: Users Free Documents Appimobiliaria api-Rest vendor Laravel framework src Illuminate Database Connection.php on line 669
I’m using the version 6.11.0
of Laravel and bank Postgresql
.
Put the snippet where the query is, please.
– Glenys Mitchell
Why you awarded the email validator with the id???
– Glenys Mitchell
I am using this video-lesson: https://www.youtube.com/watch?v=nojjKw3ZmRc&list=PLwQZAwVAR7tMF5YTeD9mAN8LGqdcA55Ns&index=10
– Luiz Roberto Furtuna
Paste the code of your model contact together with the question
– Glenys Mitchell
Your table
contacts
does not have the column1
, you are wrong to generate validation.'unique:contacts,' . $contact->id
search in a specific column. Read https://laravel.com/docs/5.8/validation#Rule-Unique– Erlon Charles