I am trying to use make a put request using custom request validation. Here is my code:
api.php
Route::put('/update-pdf-resource/{resource}', 'ManagementController@updatePdfResource');
ManagementController.php
public function updatePdfResource(Resources $resource, UpdatePdfResourceRequest $request)
{
$resource->type = $request->type;
$resource->title = $request->title;
$resource->file = $request->file('file')->store('files', 'public')l
$resource->save();
return response(['message' => 'Resource updated successfully'], 201);
}
UpdatePdfResourceRequest.php
public function rules()
{
return [
'type' => 'required',
'title' => 'required',
'file' => 'required | mimes:pdf'
];
}
Now whenever I try to update a entry it sends me following error
The Request header is
It's hitting the correct route with correct data, but throwing validation error. How to solve it ?
Correction:
I just returned the $request beginning of the updatePdfResource
method & it returns an empty array ! but in header it's showing the proper payload as above !