CRUD with multi language media #1330
Replies: 2 comments
-
Based on the knowledge sources, I can see you're trying to create a CRUD with multilingual support that includes both text fields and images for each language, using Spatie's Translation and Media Library packages with Backpack. Challenges with Multilingual Media in BackpackThere are some known issues when working with translatable fields and media uploads in Backpack:
Possible SolutionsFor SVG Support with Media LibraryIf you're using [
'name' => 'image',
'type' => 'image',
'withMedia' => [
'displayConversions' => 'thumbnail',
'mimeTypes' => 'jpeg,png,jpg,gif,svg'
]
] For Multilingual MediaThere are a few approaches you can consider:
[
'name' => 'image',
'type' => 'image',
'withMedia' => [
'collection' => 'image_' . app()->getLocale(),
'displayConversions' => 'thumbnail'
]
]
public function setImageAttribute($value)
{
$attribute_name = "image";
$disk = "uploads";
$destination_path = "uploads/".$this->table;
// Your upload logic here
// Return the attribute value for translation
return $this->attributes['image'];
}
Current LimitationsIt's worth noting that there are some ongoing issues with the integration between Backpack's upload fields and Spatie's Media Library, especially in relationship fields as mentioned in this GitHub issue. The Backpack team is working on a major refactoring of the uploader functionality to address these issues. RecommendationBased on the available information, I would recommend:
If you continue to experience problems, you might want to wait for the upcoming uploader refactoring that the Backpack team is working on, as mentioned in several of the GitHub issues. ℹ️ Please note our AI Bot does not reply to follow-ups, this will be the only AI answer in this thread. If the AI helped you find the answer, please mark it as answered or write details below so it can learn. Then close the conversation. If not, please give more information for when a human reads this. ℹ️ Relevant sources: Github Issue (closed): [Bug] upload_multiple field translation missing |
Beta Was this translation helpful? Give feedback.
-
Hey @blondie63 AFAIK, the Spatie Media Library doesn't save files per translation. You can use Yes, this will need a column in the DB and you will find it working separately for each language. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I need to create a Crud to manage some settings, each setting has multilingual text fields and also images for each language. I am using Spatie Translation and Spatie Media Library but I found these problems:
if I use 'type' => 'image', and 'withMedia' I cannot upload images like svg
if I use 'type' => 'upload', and 'withFiles(true)' then I am forced to have the fields on the table even if they are not used
What is the right way to create a Crud that meets my needs
Thanks a lot for the help
Beta Was this translation helpful? Give feedback.
All reactions