dmitrybubyakin / nova-medialibrary-field

Laravel Nova field for managing the Spatie media library
MIT License
262 stars 62 forks source link

Using a thumbnail instead of original image #141

Closed bilogic closed 3 years ago

bilogic commented 3 years ago

Hi,

Is there a way to specify using a thumbnail in index, i find that it currently loads the original image. Thank you.

dmitrybubyakin commented 3 years ago

@bilogic https://github.com/dmitrybubyakin/nova-medialibrary-field#previewusing

bilogic commented 3 years ago

Beautiful! Thanks! Is there a built-in way to show the original image in a lightbox when clicked?

dmitrybubyakin commented 3 years ago

@bilogic You need to override the index field.

bilogic commented 3 years ago

Ok, got it. Thank you.

bilogic commented 3 years ago

@bilogic https://github.com/dmitrybubyakin/nova-medialibrary-field#previewusing

I realized this affects show page too.. possible to specify based on the page type?

dmitrybubyakin commented 3 years ago

@bilogic You can pass a callback in previewUsing.

bilogic commented 3 years ago

Ok, but how does that help? Let's say in index, I want to use thumb conversion, but in show, I want to use small conversion. I can update your examples for you :)

dmitrybubyakin commented 3 years ago

@bilogic Something like this (haven't tested, but should work)

Medialibrary::previewCallback(function ($media) {
    return $media->getFullUrl(request()->isIndex() ? 'index-conversion' : 'other-conversion');
})
bilogic commented 3 years ago

ok thanks let me work it out and then file a PR

bilogic commented 3 years ago
Medialibrary::previewCallback(function ($media) {
    return $media->getFullUrl(request()->isIndex() ? 'index-conversion' : 'other-conversion');
})

The most important bit ->isIndex() does not exists. Haha.

dmitrybubyakin commented 3 years ago

@bilogic It doesn't (: You're free to easily implement it https://github.com/dmitrybubyakin/nova-medialibrary-field/blob/master/src/Fields/Medialibrary.php#L349

bilogic commented 3 years ago

Anyway thanks, I thought it was a quick and easy one.