@phpmick I think laravel have fromSub method to select from subquery
Also you can find some other variants, just google it
For example - https://stackoverflow.com/questions/24823915/how-to-select-from-subquery-using-laravel-query-builder
It's outdated, but should give you an idea (I think the methods works more-less the same)