samedi 13 juillet 2019

how to validate multiple images in laravel

I'm trying to validate images, so a user should only enter five images(maximum) and also he should not be able to upload video , ai ,psd and etc. So far when I try to upload a video it shows no errors and it does not upload the product, if I try to upload other files like psd it shows an error Illuminate \ Http \ Exceptions \ PostTooLargeException. How can I validate only five images(maximum) to be uploaded and also only these type of files mimes:jpeg,jpg,png?

code

Controller

   public function store(Request $request) 
   {
    $this->validate(
        $request, 
        [
        'photos' => 'required',
        'photos.*' => '|mimes:jpeg,jpg,png',
       )];

     foreach ($request->photos as $photo) {
        $filename = $photo->store('public/photos');
        ProductsPhoto::create([
            'product_id' => $product->id,
            'filename' => $filename
        ]);
    } 
   }

Blade template

     <input multiple="multiple" name="photos[]" type="file">



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire