spatie / laravel-medialibrary

Associate files with Eloquent models
https://spatie.be/docs/laravel-medialibrary
MIT License
5.78k stars 1.08k forks source link

Calling toHtml on Media model doesn't return alt, unless defined via attributes #3535

Closed kikky7 closed 9 months ago

kikky7 commented 9 months ago

If I don't specify alt within attributes, then output has no alt tag, looking into responsiveImageWithPlaceholder.blade.php, there is also no alt attribute. Isn't name column here to be used as alt?

$media = $this->getFirstMedia('image');

return $media
            ->img()
            ->attributes([
                'class' => 'w-full h-full object-cover object-center',
                'alt' => $media->name, // without this no alt in the output
            ])
            ->toHtml();