I'm developing a laravel api using resource controller. There I have to use PUT method for updating something.
When I try to pass data through body with form-data the validation error happens. I have to pass the data through param.
Is this normal for laravel resource controller? If so why?
Here's my code.
public function update(RoleRequest $request, string $id)
{
$data = Role::find($id);
$new_data = [
'name' => $request->name
];
$data->update($new_data);
return $this->apiResponse(true, 'role updated successfully', $data, 200);
}
Here's the validation error.
{
"success": false,
"message": "Validation errors",
"data": {
"name": [
"The name field is required."
]
}
}
_method=PUTas a param (or in the form data!)namewhy are you surprised the validation fails if you don't supply that attribute? If you want different validation rules for PUT or PATCH, use a different Request class.