Hello . You explained very very briefly. I think the rest of us don't know what you are
Jan 24, 2023
4
Level 3
Need help turning SQL query into Eloquent statement
Here is a sanitized version of the query itself:
SELECT
[...]
FROM
(
(SELECT [...] FROM tableA) as a
INNER JOIN
(SELECT [...] FROM tableB) as b
ON
a.date = b.date
)
LEFT JOIN
sites
ON
a.sites_id = sites.id
Here is the closest I've gotten:
DB::select('[...]')
->fromSub(function ($query) {
$tableA = DB::table('tableA')->select('[...] as a');
$tableB = DB::table('tableB')->select('[...] as b');
$query->table($tableA)
->join($tableB, 'a.date', '=', 'b.date')
->select('tableA.*', 'tableB.*');
})
->join('sites', 'a.sites_id', '=', 'sites.id')
->get();
That doesn't quite do it though. All I've gotten so far is errors, typically Call to undefined method as I trial-and-error my way through this.
Help is very appreciated, thank you! Let me know if there's any more context I can provide that would be helpful.
Please or to participate in this conversation.