Laravel : $request->hasFile() is not working Laravel : $request->hasFile() is not working laravel laravel

Laravel : $request->hasFile() is not working


If everything's gonna correct in your code, then you might be missing the enctype, I had also missed that at startup,

<form action="{{ route('store') }}" method="POST" enctype="multipart/form-data">

Or if you use Form Helper, that enctype easily included with file=true field.

{!! Form::open(['route' => ['store'], 'file' => true]) !!}


You need to check php directive upload_max_filesize in php.ini.

Generally its size is 2M defined as default.If you upload file greater than this size

Laravel function

$request->hasFile()

will return false

Hope it helps!!


Be sure you have an 'files' => true option in your form definition like below:

{!! Form::open(['route' => ['uploadimage'], 'files' => true]) !!}

This option causes that your form will be render with enctype="multipart/form-data" option in HTML form tag, which is mandatory to upload a file using form

Or, if you are using html form, then make sure you have enctype="multipart/form-data" like:

<form action="{{ route('store') }}" method="POST" enctype="multipart/form-data">