Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to paginate in Laravel when using Modell::find(array())

I'm grabbing some data in Laravel using the find method and only grabbing the id's I want:

$my_ids = array(1,4,5,10); $results = Model::find($my_ids);

However, if I try to paginate via Model::find($my_ids)->paginate(10), it throws the error: Call to undefined method Illuminate\Database\Eloquent\Collection::paginate().

How can I query to only get specific model Id's back from the database while also using pagination?

like image 800
justinl Avatar asked Oct 27 '25 02:10

justinl


1 Answers

Turns out I can use this syntax:

$results = Model::whereIn('id', $my_ids)->paginate(10);

like image 96
justinl Avatar answered Oct 29 '25 00:10

justinl