我正在使用 Laravel 5 并且我有一个用户表,以及两个包含用户之间关系的表“客户”和“员工”。
我想获得登录用户的所有客户和员工。
我有一个原始查询,它可以正常工作:
select users.* from clients, users
where clients.id_marchand = 8 and users.id = clients.id_client
union
select users.* from employes, users
where employes.id_marchand = 8 and users.id = employes.id_employe
order by `seen` asc, `created_at` desc limit 25 offset 0
Run Code Online (Sandbox Code Playgroud)
原始查询返回一个数组,但我需要获得一个 Eloquent 集合,例如:
return $this->model
->where(...)
->oldest('seen')
->latest()
->paginate($n);
Run Code Online (Sandbox Code Playgroud)
我尝试了很多不同的可能性,但它们都不起作用......
有没有办法用子查询或其他方法来做到这一点?