ebess / advanced-nova-media-library

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

Can't have a single image upload anymore? #211

Open Manoz opened 4 years ago

Manoz commented 4 years ago

Hello,

I'm struggling to make this package work on lastest version of Laravel and Nova. Basically I created a field where users can upload one image but looks like the field still display the button "Add new media" under my image.

Here my field:

Images::make('Image', 'image')
    ->conversionOnIndexView('thumb')
    ->croppingConfigs(['ratio' => 500 / 330]),

Here's my model:

use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Spatie\MediaLibrary\InteractsWithMedia;

class SomeModel extends Model implements HasMedia
{
    use InteractsWithMedia;

    ...

    public function registerMediaConversions(Media $media = null): void
    {
        $this->addMediaConversion('thumb')
            ->width(500)
            ->height(330);
    }

}

And here's a preview of my field: image

Might be related to #117 but the singleFile() method doesn't work anymore on Spatie's Laravel medialibrairie v8 :/

bcoelhodev commented 4 years ago

Add a collection with single file.

Like this

public function registerMediaCollections(): void
{
        $this->addMediaCollection('image')
            ->singleFile();
}

You can only add one file but it still display "Add New Media" / "Upload New Media".

Manoz commented 4 years ago

Thanks @bcoelhonqda but it doesn't work. Any way to make this work like before and don't add the "Add new media" button for single medias?

stuartcusackie commented 3 years ago

Similar problems here. There doesn't seem to be a way to prevent the user from adding more than one file through the media library field.

You can put a validation rule on the field, e.g. ->rules('nullable', 'max:1'), and that will prevent the form from submitting when multiple files are chosen, however, no validation error is displayed.

Manoz commented 3 years ago

@stuartcusackie yeah unfortunately that's more a "workaround" than a real fix :( Btw I've updated all my dependencies to latest versions from spatie and still have the same issue

figurluk commented 3 years ago

same issue here

nrueckmann commented 2 years ago

Issue does not happen to me:

spatie/laravel-medialibrary:10.3.2 laravel/framework:9.9.0 laravel/nova:4.2.5

LiamKarlMitchell commented 1 year ago

Any update on a fix for this?

iamaks1993 commented 1 year ago

Any solution?