advanced-nova-media-library icon indicating copy to clipboard operation
advanced-nova-media-library copied to clipboard

Can't have a single image upload anymore?

Open Manoz opened this issue 3 years ago • 8 comments

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.

  • Laravel version: 8.9
  • Nova version: 3.12.1
  • ANML version: 3.3.0

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 :/

Manoz avatar Oct 22 '20 08:10 Manoz

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".

bcoelhodev avatar Oct 22 '20 15:10 bcoelhodev

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?

Manoz avatar Oct 23 '20 06:10 Manoz

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.

stuartcusackie avatar Nov 01 '20 12:11 stuartcusackie

@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

Manoz avatar Nov 16 '20 10:11 Manoz

same issue here

figurluk avatar Aug 30 '21 13:08 figurluk

Issue does not happen to me:

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

nrueckmann avatar Apr 28 '22 10:04 nrueckmann

Any update on a fix for this?

LiamKarlMitchell avatar Feb 04 '23 05:02 LiamKarlMitchell

Any solution?

iamaks1993 avatar Oct 27 '23 06:10 iamaks1993