What is the best approach?
What is the best approach to upload images but also being able to manage and translate the name and alt text? Has anyone ever done this before? Or can anyone push me in the right direction?
I'm already using this package in my project
mvenghaus/filament-plugin-translatable-inline
. So I was thinking of using this package spatie-laravel-media-library-plugin
but I don't get it in my translation text input. Does anyone have any alternatives on how I can achieve it? Thank already if someone can help me1 Reply
I'll probably encounter something like this as well soon, perhaps this can help you in the right direction. Say you're using spatie media library, and say you've set up the media library correct - i'd add the
Translatable
, HasMedia
and InteractsWithMedia
to the relevant model. The model should contain a protected $translatable = ['name', 'alt_text']
with your fields.
I'm unsure if spatie/laravel-medialibrary
directly supports translations for media attributes as I haven't personally used it yet. But you could extend the media libraries functionality through custom properties to the media item that you can translate like:
https://spatie.be/docs/laravel-medialibrary/v11/advanced-usage/using-custom-properties
Then modify the filament resource to accommodate the custom form field to allow them to input translations or not.
You should be able to acces the translation in the view or other like so:
$mediaItem->getCustomProperty('name')['en']; // Access English name
You could replace the 'en' or whatever with something dynamic of course.Using custom properties | laravel-medialibrary
laravel-medialibrary