dmitrybubyakin / nova-medialibrary-field

Laravel Nova field for managing the Spatie media library
MIT License
264 stars 61 forks source link

Fallback url #126

Open martin-ro opened 3 years ago

martin-ro commented 3 years ago

When using a fallack url no image is displayed. For example on a model like so:

public function registerMediaCollections(): void
    {
        $this->addMediaCollection('user-photos')
            ->useFallbackUrl(asset('images/default-user-photo.png'));
    }

The image field is blank. I also wasnt able to get it to work with the previewUsing and mediaOnIndex methods.

Any idea what the issue is? Thanks!

dmitrybubyakin commented 3 years ago

@martin-ro Hi. Looks like it's a bug. I'll look into it.

bilogic commented 3 years ago

Hi, any idea where the issue might be? I can try to find a solution.

bilogic commented 3 years ago

@dmitrybubyakin

Is there where the problem might be? https://github.com/dmitrybubyakin/nova-medialibrary-field/blob/afaa894ddde69f0006d355f18c0bf8bf9811f8b9/resources/js/components/Medialibrary/MediaPreview.vue#L31-L37

dmitrybubyakin commented 3 years ago

@bilogic I think it's ok. It might be something else.

bilogic commented 3 years ago

I see.. sorry I don't know Vue, can't help much.

petarthewizard commented 3 years ago

This is method is not even available in my version, for some reason, and downloaded this a few days ago. Is this available only on the dev branch?

petarthewizard commented 3 years ago

I figured that useFallbackUrl is media-library specific method. So, I can, also, testify that it doesn't use the fallback URL when you delete an image.

petarthewizard commented 3 years ago

@dmitrybubyakin I couldn't find the code, but could the problem be that getMedia returns an empty collection when there is no media even when using useFallbackUrl. I think that you have to make a call to getFirstMediaUrl($collectionName) to get the fallback url.

bilogic commented 3 years ago

@dmitrybubyakin I also managed to get fallbackUrl working and have the same conclusion as @petethewizard. Don't think this is a bug.