rexlmanu/laravel-tmdb

Laravel SDK for the TMDB API

Fund package maintenance!
chiiya

dev-master 2023-07-09 16:54 UTC

This package is not auto-updated.

Last update: 2024-05-13 19:31:41 UTC


README

Latest Version on Packagist GitHub Code Style Action Status Total Downloads

Laravel package for using the TMDB API.

Installation

You can install the package via composer:

composer require chiiya/laravel-tmdb

Next, configure your TMDB API token in your .env file. This should be your API Read Access Token (v4 auth):

TMDB_API_TOKEN="eyJh..."

Usage

This package is a thin wrapper around chiiya/tmdb-php, that allows you to directly inject the repositories in your application:

use Chiiya\Tmdb\Repositories\MovieRepository;
use Chiiya\Tmdb\Query\AppendToResponse;

class TmdbService {
    public function __construct(
        private MovieRepository $movies,
    )
    
    public function handle(): void
    {
        $this->movies->getMovie(550);
        $this->movies->getPopular();
        $movie = $this->movies->getMovie(550, [
            new AppendToResponse([
                AppendToResponse::IMAGES,
                AppendToResponse::WATCH_PROVIDERS,
            ]),
        ]);
        $movie->watch_providers['US']->flatrate[0]->provider_name;
    }
}

For documentation on method signatures, check out chiiya/tmdb-php.

Testing

Since this package uses the Laravel HTTP Client under the hood to perform API requests, you may simply call Http::fake() to fake responses in your tests. For mocking specific responses, check out the example responses.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.