Rav
Rav

Reputation: 1470

How to paginate records from API in Laravel

How to paginate/access in any reasonable way remote model based on external API? For Laravel 4 there's a nice library called Trucker (https://github.com/indatus/trucker), but I've found absolutely no other tool for L5.

The only think I actually care about is how to accomplish code similar to this:

$users = UserFromApi::get(); // Get all users from api
$activeUsers = UserFromApi::where('active', 1)->get();

...with UserFromApi being REMOTE API, not in the database nor anywhere.

I can use simple get_file_contents() method, so it's not the request that's problematic, but the approach to do it in Laravel 5, so I can use a model.

Upvotes: 1

Views: 1355

Answers (1)

Amir Bar
Amir Bar

Reputation: 3105

look at laravel docs for collections http://laravel.com/docs/master/collections#method-where

so if you got some data from api, parse it to array and do something like:

$collection = collect($data);

$filtered = $collection->where('active', 1);

Upvotes: 1

Related Questions