Eloquent query results are returning all translations #433
Unanswered
binaryfire
asked this question in
Q&A
Replies: 2 comments 3 replies
-
Your expectation is correct. Example: $apples = Apple::all();
foreach ($apples as $apple) {
echo $apple->name;
} This should echo all the translated values. |
Beta Was this translation helpful? Give feedback.
3 replies
-
I am facing a similar issue on Laravel 11 with the latest laravel-translate, using MariaDB 11.3. With a model setup like this: class FaqQuestion extends Model
{
use HasTranslations;
protected $table = 'faq_questions';
protected $fillable = [
'question',
'answer',
'category_id',
];
public $translatable = ['question', 'answer'];
} With the following migration: Schema::create('faq_questions', function (Blueprint $table) {
$table->id();
$table->json('question');
$table->json('answer');
$table->foreignId('category_id')->constrained()->cascadeOnDelete();
$table->timestamps();
}); Calling [
"id" => 1
"question" => "{"nl":"Wat is Nederlands?","en":"What is English?"}"
"answer" => "{"nl":"<p>Nederlands antwoord.</p>","en":"<p>English answer.</p>"}"
"category_id" => 1
"created_at" => "2025-02-03 08:22:01"
"updated_at" => "2025-02-03 08:22:01"
] All available languages are provided rather than just the current locale (or fallback). Is there a configuration I could've missed here? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all
Not sure if I'm doing something wrong, but when I get multiple results using Eloquent's
get()
orall()
I'm getting all the translations. Is that supposed to be happening? I expected that the package would just return the current locale's translation for the attributeBeta Was this translation helpful? Give feedback.
All reactions