Note: this is laravel 5.3
Basically I'm running a query when a user selects arabic translation.. the full sql looks like this
select s.ref, t.text as ref_ar
FROM stores AS s
INNER JOIN
(SELECT item, text
FROM translator_translations
WHERE locale ='ar'
AND namespace ='*'
AND item like 'store.ref%'
) AS t
ON substring(s.ref_translation from 14 for 26) = t.item;
don't see much documentation on subqueries on the official Laravel docs (there are inner join stuff but not good enough) and the SO advice seems extra-hacky.. advice?
context
this will be used as a scope inside a model, so this works for example:
public function scopeFilterLanguage($query, $language_id)
{
if (!$language_id || intval($language_id) != LanguageConstants::ARABIC_LANGUAGE_ID) {
return $query;
}
return $query->whereRaw("
substring(ref_translation from 14 for 26) in
(select item
from
translator_translations
where
locale ='ar' and namespace ='*'
and
item like 'store.ref%')");
}
but it doesn't give me what i want. (ie i have to use the bigger version at the start of this post)