Laravel 5 check if file uploaded or not using hasFile or isValid


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....


July 16, 2017 | 585 Viewer | Category : PHP Laravel

Related Posts: