Laravel-medialibrary: both lazy & attributes give "undefined method"

Created on 5 Sep 2020  路  4Comments  路  Source: spatie/laravel-medialibrary

from the docs

  • ex.
$item->getFirstMedia('cover')->attributes(['class' => 'my-class'])->lazy()
Call to undefined method Spatie\MediaLibrary\MediaCollections\Models\Media::attributes()
// &
Call to undefined method Spatie\MediaLibrary\MediaCollections\Models\Media::lazy()

might be related to using ->withResponsiveImages() but i could be wrong, if yes i could PR some clarification on the rdme

Most helpful comment

Feel free to PR any improvements you see. Be sure to include tests.

All 4 comments

I think the docs were missing an img() call.

$item->getFirstMedia('cover')->img()->attributes(['class' => 'my-class'])->lazy()

I've correct this. If there are other things wrong, feel free to PR fixes.

it wont work in its current state if the $item->getFirstMedia('cover') or $item->getFirstMedia('cover')->img() is null

to make this global and future prof, i think we can wrap both methods with optional, if its ok with u i can make a PR.

PS:
->img()->attributes(['class' => 'my-class']) could be changed to ->img('', ['class' => 'my-class'])

Feel free to PR any improvements you see. Be sure to include tests.

can u reopen the ticket so we can easily track it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Radiergummi picture Radiergummi  路  4Comments

ideadx picture ideadx  路  4Comments

brendt picture brendt  路  4Comments

mohammad6006 picture mohammad6006  路  4Comments

aaronfullerton picture aaronfullerton  路  4Comments