In this post, i will tell you how to check if file is present or not on the request using hasFile
method.
Laravel provides flexibility for uploading file with validation. hasFile method is one of them to check if file exist with request object or not.
You can also use isValid
method to verify if file is present or not while uploading the file in Laravel 5.3.
See the following example :
Example 1:
- public function uploadFile(Request $request)
- {
- if($request->hasFile('file_name')) {
- dd('write code here');
- }
- }
- public function uploadFile(Request $request)
- {
- if ($request->file('file_name')->isValid()) {
- dd('write code here');
- }
- }