Laravel : $request->hasFile() is not working
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">
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 a file greater than this size, the Laravel function
$request->hasFile()
will return false.