php-tmdb / laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the wtfzdotnet/php-tmdb-api library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How does Pagination work?

benjivm opened this issue · comments

commented

I'm wondering if it's possible to use Laravel's pagination with this, or if there's a way to do it on the API itself? When I rundd(get_class_methods($popular)), for example, I can see these:

1 => "getPage"
 2 => "setTotalPages"
 3 => "getTotalPages"
 4 => "setTotalResults"
 5 => "getTotalResults"

But I have absolutely no idea how to access them. Could anyone point me in the right direction?

Hi @gmask,

$repository = new \Tmdb\Repository\MovieRepository($client);
$topRated = $repository->getTopRated(array('page' => 3));

For any more examples I would advise you to review the base repository, https://github.com/php-tmdb/api/blob/2.0/README.md

As I don't use laravel I can't answer your specific pagination question.

commented

@laravelish You're awesome, thank you; it works perfectly!

@gmask hello sir can u send an example for the pagination.

commented

@limuel567 In Laravel it's very simple, here's an example search() implementation:

$searchMovies = Tmdb::getSearchApi()->searchMovies($request->input('query'), ['page' => $request->input('page')]);

$movies = new LengthAwarePaginator($searchMovies['results'], $searchMovies['total_results'], 20, $request->input('page'), ['path' => $request->url()]);