andersao / andersao/l5-repository

complicated relationship - pagination / general help

未关闭
#300 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
help wanted
主要语言
PHP
星标
4.2k
派生
880
PR 合并指标
30 天内没有已合并 PR

描述

I have a seller, to get his buyers.. I am currently doing in the Seller Model:

```
public function Clients($id=null)
{
$query = "
SELECT o.user_id FROM orders o
INNER JOIN order_items oi
ON oi.order_id = o.id
INNER JOIN products p
ON p.id = oi.product_id
WHERE p.user_id = " . $this->id;

if ( $id )
$query .= " AND o.user_id = " . $id;

$results = \DB::select($query);

$collection = collect([]);

foreach ($results as $user) {
$collection->push( \App\Entities\User::find($user->user_id) );
}

return $collection;
}
```

Now I have an endpoint where I need to display sellers' buyers.. so right now I do something like:

\Auth::user()->id->clients()... which is working

But as i am using this awesome library, i would like to be able to convert this to use pagination? & then view transformed results...

i cannot think how i can do this? i cant have a repository

Any hints would be appreciated.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。