from the docs
$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
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
Most helpful comment
Feel free to PR any improvements you see. Be sure to include tests.