Laravel 4 查询生成器原始加入数据库

Laravel 4 query builder join DB raw

我正在使用 laravel 4 并有 sql 这样的查询

select a.*, v.* from (select * from application order by id desc)a join vacancy v on a.vacancy_id = v.id group by a.email

我的问题是如何在查询生成器中编写

您可以试试这样的方法。 (未经测试)

$subQuery = DB::table('application')->orderBy('id', 'desc');

$result = DB::table(\DB::raw("({$subQuery->toSql()}) as a"))
    ->mergeBindings($subQuery)
    ->selectRaw("a.*, v.*")
    ->join('vacancy as v', 'a.vancancy_id', 'v.id')
    ->groupBy('a.email')
    ->get();