问题描述
我有一个可以正常工作但无法使用分页的查询如何转换为 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 & Project 的模型。
with recursive cte as (
select e.result_data_branch_id as branch_id,e.result_data_branch_id as topBranch_id,e.result_data_branch_name as branch_name
from efront e
where result_data_branch_parent_id is null
union all
select e.result_data_branch_id,cte.topBranch_id,cte.branch_name
from efront e join
cte
on e.result_data_branch_parent_id = cte.branch_id
)
基于laravel documentation