Home Laravel How to check uploaded file is empty or not in Laravel?

How to check uploaded file is empty or not in Laravel?

by Shahriar Sagor

Today, now in this post i will show you How to check uploaded file is empty or not in Laravel? From here we will learn how to check the uploaded file is present or not on on request object in laravel 6, laravel 7 and laravel 8 any version of application.

If we are work on file the uploading or image uploading then we have to need to check the file array is empty or not. In Laravel provide us two way to check the file is present or not on request object.

Now in bellow example we can see both how to check. It is a very simple example on that way we can simply check this.

Example 1:
public function fileUpload(Request $request)
{
	if ($request->file('image')->isValid()) {
	    dd('write code here');
	}
}
Example 2:
public function fileUpload(Request $request)
{
	if ($request->hasFile('image')) {
	    dd('write code here');
	}
}

Read Also: How to implement infinite ajax scroll pagination in Laravel?

Thanks for read. I hope it help you. For more you can follow us on facebook

close

You may also like