Skip to content
Advertisement

How to make sql nested/sub query in PHP

I’m struggling with implementing SQL query into my php code.

The query:

JavaScript

I was able to prepare only this part:

JavaScript

And it works, but it is only responsible for the nested part, for the subquery if I can call it like this. Can someone share any thoughts?

Advertisement

Answer

DB::table() usually receive table name as a string, but it can also receive Closure or an IlluminateDatabaseQueryBuilder instance, so this should do the trick for Laravel’s select from subquery:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement