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 ?
- Laravel - chmod(storage/oauth-private.key): Operation failed: Operation not permitted
- Laravel 7.x and 6.x datatables example from scratch
- How to compress PNG image using pngquant in PHP?
- Laravel 7.x and 6.x Chart example using Charts Package
- Guzzle http client GET and POST request example in Laravel 5
- Laravel schema default current timestamp value example
- Laravel 7.x and 6.x Get Site URL Examples
- Convert object to array in laravel 7.x and 6.x example