Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload a file with PUT method on POSTMAN

Hi I'm getting an error when I try to Update image in the postman

My Controller

   $validator =    Validator::make($request->all(), [
    'category_id'=> 'required',      
    'product_name'=> 'required', 
    'product_description'=> 'required',      
    'product_img'=> 'required' 
 ] );
    if ($validator -> fails()) {
        return $this->sendError('error validation', $validator->errors());
    }
    $product = Product::findOrFail($id) ;

    $product->category_id = $request->input('category_id');
    $product->subcat_id = $request->input('subcat_id');
    $product->product_name = $request->input('product_name');
    $product->product_description = $request->input('product_description');
    $product->product_properties = $request->input('product_properties');
    $product->product_img =  $request->file('product_img')->store('images');
    $product->product_pdf =  $request->file('product_pdf')->store('files');
    if($product->update()){
        return $this->sendResponse($product->toArray() , 'Product Updated Succesfully');
    }

My PostMan row

"product_img":"Downloads/screencapture-file-C-Users-gkpro-Desktop-ui-Semantic-UI-master-examples-navbar-html-2019-01-03-20_31_47.png"

I get this error

Call to a member function store() on null

like image 501
Kareem Elsharkawy Avatar asked Dec 18 '22 18:12

Kareem Elsharkawy


1 Answers

If you wanna use form-data to upload image with PUT method, here the trick,

add _method: PUT in form-data

enter image description here

like image 79
Kyaw Kyaw Soe Avatar answered Dec 20 '22 16:12

Kyaw Kyaw Soe