It is very easy to check if uploaded file or image empty or not if you are using core PHP. But as we know laravel 5 provide us object of file, So we can not determine using empty().
However, we can simply do it using hasFile() and isValid() of laravel predefine. So i am going to give you basic example of both function one by one. So let's simply see both example and use it.
Using hasFile()
public function uploadFileORImage(Request $request)
{
if($request->hasFile('input_file')) {
dd('here you can write code');
}
}
Using isValid()
public function uploadFileORImage(Request $request)
{
if ($request->file('input_file')->isValid()) {
dd('here you can write code');
}
}
I hope you found your solution....
Do you like below Tutorials ?
- PHP Laravel 5.5 - import export data into excel and csv using maatwebsite
- Laravel 7.x and 6.x create custom facade example from scratch
- Node JS - Get Real time online users counter using socket io example
- PHP Laravel 7.x and 6.x - Bootstrap Admin Theme Integration example from scratch
- MySQL Query - How to select records of today to next Sunday ?
- Laravel 7.x and 6.x - username custom validation example
- Laravel 5.5 - Import Extract zip file using chumper/zipper package
- PHP Laravel Set Custom Validation Error Messages Example