Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to a member function store() on null - laravel 5.4

I'm trying to upload an image though everytime I submit it's returning that the store() on null error. I've set the form to enctype="multipart/form-data" which hasn't helped.

Can anyone point me in the right direction?

Thanks.

Function inside the controller

public function store(Request $request){

  $file = $request->file('imgUpload1')->store('images');
  return back();

}

Form below:

<form action="/imgupload" method="POST" enctype="multipart/form-data">
  {{ csrf_field() }}
  <div class="form-group">
     <label for="imgUpload1">File input</label>
     <input type="file" id="imgUpload1">
  </div>
    <button type="submit" class="btn btn-primary">Submit</button>
</form>
like image 952
Erasersharp Avatar asked Feb 07 '17 11:02

Erasersharp


1 Answers

I had the same issue what I did to fix is in the opening form tag add enctype="multipart/form-data" that should fix it. Without it laravel would not understand the file.

like:

<form method="POST" enctype="multipart/form-data" name="formName">
like image 52
Jose Hernandez Avatar answered Sep 20 '22 09:09

Jose Hernandez