How to use Laravel paginate with a manual query?

Asked

Viewed 919 times

3

I have a query manual on my model, and I want to return to view of blade the result of this paging query. 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]);
}
  • 1

    Ever tried to change the get() for paginate() in the method getClosed() of your model?

  • 1

    @Amandalima worked . Thank you very much, can formulate the answer so that I accept it?

1 answer

4


In your model, change the get() for paginate() in the method Return getClosed().

Will stay like this:

public function getClosed()
{
   return $this->where('situation', '=', 4)->orderBy('priority', 'desc')->paginate(15);
}
  • perfect +1 ...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.