Dyin Razeeb
Dyin Razeeb

Reputation: 15

Check upload file validation -Laravel

Only validation check if file upload. (file exist) if not upload file then need not check validation (In laravel validation)

Upvotes: 0

Views: 130

Answers (2)

David Olsson
David Olsson

Reputation: 21

Be more specific and add some code if you want a better answer like @nakov wrote.

You can also cast a validation when you have a file uploaded with an if statement like this:

if ($request->hasfile('photo')) {
    $request->validate(['photo' => 'image|mimes:jpeg,bmp,png'])
}

Upvotes: 0

nakov
nakov

Reputation: 14268

You should share some code so you get a better help. But you can use the nullable rule in order to allow empty data like this:

// as an example
$request->validate([
    'photo' => 'nullable|mimes:jpeg,bmp,png'
]);

Upvotes: 1

Related Questions