andersao / andersao/l5-repository

complicated relationship - pagination / general help

Abierto
#300 1 comentario 0 reacciones 0 asignados Ver en GitHub
help wanted
Lenguaje dominante
PHP
Estrellas
4.2k
Forks
880
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.