How to use laravel paginate with a manual query?

3

I have a manual query in my model, and I want to return to view of blade the result of this query with pagination. Is there any way?

  

Model

class Ticket extends Model
{
    protected $fillable = [
        'id',
        'title',
        'description',
        'created_at',
        'priority',
        'g',
        'u',
        't',
        'provide_closure',
        'situation',
        'solution',
        'closing_date',
        'client_id',
        'ticket_type_id',
        'ticket_category_id',
        'equipment_id',
        'user_id'
    ];

    protected $table = 'ticket';

    public function getClosed()
    {
        return $this->where('situation', '=', 4)->orderBy('priority', 'desc')->get();
     }

}
  

Controller

public function getClosed()
{
    $ticket = new Ticket();
    $data = $ticket->getClosed(); //Preciso paginar isso.
    $progress = $this->getProgress();
    return view('ticket.index', ['data' => $data, 'progress' => $progress]);
}
    
asked by anonymous 06.09.2016 / 21:09

1 answer

4

On your model, change the get() by paginate() in the return of the getClosed() method.

It will look like this:

public function getClosed()
{
   return $this->where('situation', '=', 4)->orderBy('priority', 'desc')->paginate(15);
}
    
06.09.2016 / 21:18