ebess / advanced-nova-media-library

A Laravel Nova field for displaying, creating, updating and ordering a Spatie Media Library model.
596 stars 297 forks source link

Error in Uploading File and Validation #138

Open jahid56 opened 4 years ago

jahid56 commented 4 years ago

When I user Files it returns error for mimes validation. It Throws error for pdf file and when I remove mimes validation it shows error SQLSTATE[HY000]: General error: 1364 Field 'model_type' doesn't have a default value . Here is my code `

    Images::make('Banner Images', 'banners')
          ->croppable(false)
          ->singleImageRules('max:5000')
          ->hideFromIndex()
          ->rules('required'),

    Files::make('Vendor Kit', 'vendor_kit')
         ->singleMediaRules(['mimes:pdf'])
         ->hideFromIndex(),
];

`

And My Model Code Are public function registerMediaCollections() { $this->addMediaCollection('vendor_kit')->singleFile(); $this->addMediaCollection('banner'); }

narcisonunez commented 4 years ago

I found that the current issue with this is when you have the field in the database as required (not nullable). I guess that happens because they first need to save the record to be able to attach the uploaded image/file to that record. You can prevent the form from submitting without an image with the rules() method.

That will solve your current issue.