andersao/l5-repository

complicated relationship - pagination / general help

Open

#300 创建于 2016年10月21日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)PHP (4,119 star) (868 fork)batch import
help wanted

描述

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.

贡献者指南