如何将以下查询转换为Eloquent



我有一个查询可以很好地工作,但不能进行分页-如何转换为雄辩来应用分页

$projects=DB::select("select * from projects INNER JOIN(select DISTINCT * from (SELECT project_id FROM district_group_project_users where user_id='$id' UNION ALL select id from projects where created_by='$id') as sub ) as sub on sub.project_id=projects.id;");

或者,是否有其他选项可以在以下查询中添加分页?感谢

我想您有一个名为DistrictGroupProjectUser&项目

$subQuery = DistrictGroupProjectUser::select('project_id')
->where('user_id', $id)
->union(Project::select('id')->where('created_by',$id))
->distinct();
$projects = Project::joinSub($subQuery, 'sub', function ($join) {
$join->on('projects.id', '=', 'sub.projects_id');
})->paginate(20);

基于laravel文档

相关内容

  • 没有找到相关文章

最新更新