andersao/l5-repository
View on GitHubcomplicated relationship - pagination / general help
Open
#300 opened on Oct 21, 2016
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.