php-tmdb / laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the wtfzdotnet/php-tmdb-api library.
MIT License
156 stars 60 forks source link

Examples/Documentation #30

Closed kurtaking closed 8 years ago

kurtaking commented 8 years ago

Where can I find examples/documentation on all the default functions?

For example Tmdb::getMoviesApi()->getMovie($id);

How can I search for one/all movies by a specific title?

Thanks!

MarkRedeman commented 8 years ago

Hi Kurt,

You can find most of the examples in the php-tmdb/api repository. In this case you should take a look at the search movie example.

The example shows the following,

$token  = new \Tmdb\ApiToken(TMDB_API_KEY);
$client = new \Tmdb\Client($token);
$result = $client->getSearchApi()->searchMovies('batman');

Since this package includes a facade you don't have to do the setup with the API key, instead you can write,

$results = Tmdb::getSearchApi()->searchMovies('batman');

Another way to do this is to use repositories, see search/model/movie.php which shows,

$token  = new \Tmdb\ApiToken(TMDB_API_KEY);
$client = new \Tmdb\Client($token);
$query = new \Tmdb\Model\Search\SearchQuery\MovieSearchQuery();
$query->page(1);
$repository = new \Tmdb\Repository\SearchRepository($client);
$find = $repository->searchMovie('batman', $query);

Again we may use some of Laravel's magic to help construct the objects,

// Get the Movie and Search repositories from the service container
$query = App::make(\Tmdb\Model\Search\SearchQuery\MovieSearchQuery::class);
$repository = App::make(\Tmdb\Repository\SearchRepository::class);

// Search for batman and return the first page
$query->page(1);
$find = $repository->searchMovie('batman', $query);
kurtaking commented 8 years ago

Thank you! That worked perfectly.