Iam using Laravel spatie media library backage in my project: https://spatie.be/docs/laravel-medialibrary/v10/introduction
The media library shows null when trying to retrieve an image from a model using the code
$template->getMedia('templates')
Her is the Template.php model
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
class Template extends Model implements HasMedia
{
use HasFactory,InteractsWithMedia;
protected $guarded =[];
public function registerMediaConversions(Media $media = null): void
{
$this->addMediaConversion('thumb')
->width(130)
->height(130);
}
public function registerMediaCollections(): void
{
$this->addMediaCollection('templates');
}
}
and here is the blade bage where I wont retrive the images
@foreach(\App\Models\Template::all() as $template)
@foreach($template->getMedia('templates') as $key => $image)
<img src="{{$image->getUrl()}}">
@endforeach
@endforeach
I tried
dd($template->getMedia('templates'))
but it shows null items
can any one help?
