You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am working on a laravel/vue app with multi language models. Spatie/Translatable worked fine for me, until I used formData, because I needed to send an image. I had to use JSON.stringify() to convert my translate objects into JSON. In my Laravel function, when I use a Builder object to save data in database, everything works fine. for example:
this is my payload:
title: {"en":"English Title","fr":"French title"}
this works fine:
$post = Post::where('id', 1); // returns builder
$post->update($data);
// My name field in posts table after this
{"en":"Title in English","fr":"Title in French"}
But this messes up the data saved in the name field:
Post::create($data);
// Or
$post = Post::where('id', 1)->get(); // returns model
$post->update($data);
// My name field in posts table after this
{"en":"{\"en\":\"Title in English\",\"fr\":\"Title in French\"}"}
This saves the json that should be saved in the field in the first language "en". And does not save anything to the second language "fr" as it did in the first example.
I tried to json_decode it before inserting it into the database, but doesn't work.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I am working on a laravel/vue app with multi language models. Spatie/Translatable worked fine for me, until I used formData, because I needed to send an image. I had to use JSON.stringify() to convert my translate objects into JSON. In my Laravel function, when I use a Builder object to save data in database, everything works fine. for example:
this is my payload:
title: {"en":"English Title","fr":"French title"}
this works fine:
But this messes up the data saved in the name field:
This saves the json that should be saved in the field in the first language "en". And does not save anything to the second language "fr" as it did in the first example.
I tried to json_decode it before inserting it into the database, but doesn't work.
Beta Was this translation helpful? Give feedback.
All reactions