How do I solve problems with laravel 5.2 page?

2

I'm doing a query with laravel, and when I paginate, I get an error that says - The paging method does not exist (Method paginate does not exist.)

On the one hand in the controller, I call the query and page as follows:

$img_ventass = Img_venta::busqueda($request->get('raza_id'), $request->get('sexo'), $request->get('fecha_nacimiento'))->paginate(4);

and on the other hand, I make the query in the model like this:

public function scopeBusqueda($query, $raza_id, $sexo, $fecha_nacimiento){
    return $query->leftJoin('ventas', function ($leftJoin) use ($raza_id, $sexo) {
        $leftJoin->on('img_ventas.venta_id', '=', 'ventas.id')
             ->where('ventas.raza_id', '=', $raza_id)
             ->where('ventas.sexo', '=', $sexo);
    })->get();
}
    
asked by Nicolas Cantor Martinez 07.07.2017 в 07:27
source

1 answer

0

The error you have is that you are calling the get() method within the scope, which does not allow you:

  • do nested queries after calling the scope.
  • Use other filtering or selection methods such as first() or paginate() .

The solution is to remove the get () method from the scope:

public function scopeBusqueda($query, $raza_id, $sexo, $fecha_nacimiento){
    return $query->leftJoin('ventas', function ($leftJoin) use ($raza_id, $sexo) {
        $leftJoin->on('img_ventas.venta_id', '=', 'ventas.id')
             ->where('ventas.raza_id', '=', $raza_id)
             ->where('ventas.sexo', '=', $sexo);
    });
}
    
answered by 07.07.2017 / 13:14
source