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 ?
- Angular Use CKEditor Example Tutorial
- How to Use Multiple Select Dropdown in Laravel?
- Angular 9 Image Upload with Crop Example
- Files Upload on Button Click in PHP Dropzone Example
- PHP Dropzone Allow only One File to Upload Example
- PHP Dropzone Allow only Images to Upload Example
- PHP Dropzone Delete Uploaded File Example
- Livewire CRUD Laravel 7 Example