andersao/l5-repository

complicated relationship - pagination / general help

Open

#300 opened on Oct 21, 2016

View on GitHub
 (1 comment) (0 reactions) (0 assignees)PHP (4,119 stars) (868 forks)batch import
help wanted

Description

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.

Contributor guide

complicated relationship - pagination / general help · andersao/l5-repository#300 | Good First Issue