In this article, I'll show you how to check a request has file in Laravel in this article. I'll let you know that the check request in Laravel has a file. I'll present a straightforward example and a solution. The idea behind the laravel hasFile example is clear.
Many times, we need to check request input file object is empty or not in laravel. If you need, we can provide you with the request object hasFile()
method. We can check request has a file or not in the laravel controller. So let's understand in simple example code.
Example:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PostController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index(Request $request)
{
$request->validate([
'name' => 'required',
'photo' => 'required',
]);
if ($request->hasFile('photo')) {
dd($request->photo);
}
}
}
Thank you for reading this article.
Read Also: How to get the raw SQL query from the Laravel Query Builder
If you want to manage your VPS / VM Server without touching the command line go and Checkout this link. ServerAvatar allows you to quickly set up WordPress or Custom PHP websites on VPS / VM in a matter of minutes. You can host multiple websites on a single VPS / VM, configure SSL certificates, and monitor the health of your server without ever touching the command line interface.
If you have any queries or doubts about this topic please feel free to contact us. We will try to reach you.