Query is not giving proper translated data
Created 7 years ago by lckamalIs there something wrong in this query?
FaqModel::select('faqs_faqs_translations.locale','faqs_faqs_translations.answer','faqs_faqs_translations.entry_id', 'faqs_faqs.*')->join('faqs_faqs_translations', 'faqs_faqs_translations.entry_id', 'faqs_faqs.id')
->where('faqs_faqs_translations.locale', LOCALE)
->get();
Here is output when I call api url: http://almidan.dev/en/api/faq
Data looks like this:
{
"status": 1,
"token": null,
"message": "Success",
"data": [
{
"locale": "en",
"question": "ما هي رسوم استخدام الميدان؟ ",
"answer": "الميدان مجانا لاي مستخدم. ",
"entry_id": 51,
"id": 51,
"sort_order": 41,
"created_at": "2017-05-17 05:15:27",
"created_by_id": 1,
"updated_at": null,
"updated_by_id": null,
"deleted_at": null,
"category_id": 2,
"live": 1
},
...
}
piterden
—
7 years ago
Link
lckamal
—
7 years ago
This model query doesn't work:
$faqs = FaqModel::select('faqs_faqs.*', 'faqs_faqs_translations.locale','faqs_faqs_translations.question','faqs_faqs_translations.answer','faqs_faqs_translations.entry_id')
->join('faqs_faqs_translations', 'faqs_faqs_translations.entry_id', '=', 'faqs_faqs.id')
->where('faqs_faqs_translations.locale', '=', LOCALE)
->groupBy('faqs_faqs_translations.entry_id')
->get()->toArray();
This db query works:
$faqs = \DB::table('faqs_faqs_translations')
->select('faqs_faqs.*', 'faqs_faqs_translations.locale','faqs_faqs_translations.question','faqs_faqs_translations.answer','faqs_faqs_translations.entry_id')
->join('faqs_faqs', 'faqs_faqs_translations.entry_id', '=', 'faqs_faqs.id')
->where('faqs_faqs_translations.locale', '=', LOCALE)
->groupBy('faqs_faqs_translations.entry_id')
->get()->toArray();
something wrong on model translations on core?
This video can explain more: http://take.ms/WTU4V