If you substitute ->get() with ->toSql(), you should be able to see the SQL that's generated. It probably won't be quite as neat a your raw attempt, but if you could please post it, I would like to see what's going on.
Jul 19, 2016
15
Level 22
Multiple Inner joins in the same table
Hi everyone!
I try to "translate" this query into a laravel eloquent query. The query works in mysql but when I try to write it in Laravel, it fails with the message that I have an sql syntax error.
Here's the working query:
SELECT l.origin, t.value, l.value, p.value, u.value FROM datas l
inner join datas t on l.origin = t.origin
inner join datas p on p.origin = l.origin
inner join datas u on u.origin = l.origin
WHERE l.type = 'menuLevel'
and l.value = 0
and t.type='menuTitre'
and p.type='menuParent'
and u.type='menuUrl'
And here's my laravel try:
DB::table('datas l')->select('l.origin, t.value, l.value, p.value, u.value')
->join('datas t', 'l.origin', '=', 't.origin')
->join('datas p', 'p.origin', '=', 'l.origin')
->join('datas u', 'u.origin', '=', 'l.origin')
->where('l.type', 'menuLevel')
->where('l.value', 0)
->where('t.type', 'menuTitre')
->where('p.type', 'menuParent')
->where('u.type', 'menuUrl')->get();
Should I do this with the raw queries? Thanks for your time!
Please or to participate in this conversation.