Hej, tworzę API w Laravel, stworzyłem sobie requesta, który ma mi walidować dane. Gdy wszystkie dane są w porządku wszystko przechodzi i jest git, jeżeli walidacja nie przechodzi, Laravel rzuca 404 i to cały dokument HTML. Routingi api mam w routes/api.php
.
Metoda update
public function update(UserUpdate $request, $id)
{
$user = User::find($id)->update($request->validated());
if($user) {
return [
'status' => '200',
'success' => true,
'message' => 'User has been updated'
];
}
}
Walidacja Form Request
public function rules()
{
return [
'name' => 'string',
'surname' => 'string',
'email' => [
'string',
Rule::unique('users')->ignore($this->id)
],
];
}
public function messages() {
return [
'email.unique' => 'User with this email exist',
];
}