In my project users can upload stuff and attach an image. I have a controller where I do a isValid check on the file input. Everything works great as long as you select a file. When I don't select a file I get this error
Call to a member function isValid() on null
On this line of code:
if (Input::file('image')->isValid())
The error is obvious since I don't select an image but I actually have no idea how I can fix this.
If anyone can help I'd be very happy :) Thanks in advance!
add enctype="multipart/form-data"
to your form
First you need to check if your request is containing that file / input or not.
Determining If A File Was Uploaded
if (Request::hasFile('image'))
{
/*Determining If An Uploaded File Is Valid*/
if (Request::file('image')->isValid())
{
//
}
}
Just for your info also make sure you are getting file while posting.
Add attribute enctype="multipart/form-data"
in your HTML Form Element.
You can use any of Input and Request facade.
Input class is also referencing to \Illuminate\Http\Request
in laravel
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With