0

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 enter image description here

The Request header is

enter image description here

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 !

Osman Rafi
  • 938
  • 1
  • 16
  • 37

1 Answers1

0

Requests should always come first

change it

public function updatePdfResource(Resources $resource, UpdatePdfResourceRequest $request)

to this

public function updatePdfResource(UpdatePdfResourceRequest $request, Resources $resource)

and you have a syntax error in your code "l" instead of ";"

->store('files', 'public')l
Kongulov
  • 1,156
  • 2
  • 9
  • 19