How can I use the find_in_set() with laravel query builder. Here is my raw query:
SELECT *
FROM table1 as t1
LEFT JOIN table2 as t2 ON find_in_set(t2.country, t1.fk_country_id)
How can I use the find_in_set() with laravel query builder. Here is my raw query:
SELECT *
FROM table1 as t1
LEFT JOIN table2 as t2 ON find_in_set(t2.country, t1.fk_country_id)
Using
$join->on(
was generating an incorrect query in my case (Laravel 5.4).The incorrect SQL generated was like
t1 left join t2 on find_in_set(t2.tag, t1.tags) = where t1.foo..
Here,
whereRaw
worked for meReference: From issue referring Laravel 5.5 (https://github.com/laravel/framework/issues/23488)
You can use
DB::raw
like asyou can use DB:raw as in
===================
Edit : Uchiha answer is the accurate one, since laravel "on" requires 3 arguments: a field, operator,field . i.e
on('table1.id','=','table2.id')