dariusiii / tmdb-laravel
Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the wtfzdotnet/php-tmdb-api library.
Requires
- php: >=8.3
- guzzlehttp/guzzle: ^7.2
- illuminate/support: ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
- nyholm/psr7: ^1.8
- php-tmdb/api: ^6.0
Requires (Dev)
- doctrine/cache: ^2.2
- illuminate/events: ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
- monolog/monolog: ^3.0
- phpunit/phpunit: ^12.0
- psr/event-dispatcher: ^1.0
- symfony/event-dispatcher: ^6.0|^7.0
Suggests
- doctrine/cache: Required if you want to make use of caching features.
- monolog/monolog: Required if you want to make use of logging features.
- dev-master
- 13.0
- 12.1.2
- 12.1.1
- 12.1
- 12.0.3
- 12.0.2
- 12.0.1
- 12.0
- v7.0.0
- v6.0.2
- v6.0.1
- v6.0.0
- v5.0.0
- v4.0.5
- v4.0.4
- v4.0.3.1
- v4.0.3
- v4.0.2.2
- v4.0.2.1
- v4.0.2
- v4.0.1
- v4.0.0
- v3.1
- v3.0.1.1
- v3.0.1
- v3.0.0
- v2.1.0
- v2.0.1
- v2.0.0
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1
This package is auto-updated.
Last update: 2026-03-20 15:41:17 UTC
README
A Laravel package that provides easy access to the php-tmdb/api TMDB (The Movie Database) API wrapper.
This package comes with a service provider that configures the Tmdb\Client and registers it to the IoC container.
Supports Laravel 8 through 13.
Installation
Install Composer
$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
Add the following to your require block in composer.json config
"dariusiii/tmdb-laravel": "^2.0"
or just run the following command in your project:
composer require dariusiii/tmdb-laravel
Configuration
Laravel will auto-discover the package on supported versions. If you prefer to register it manually, add the service provider to config/app.php:
'providers' => array( // other service providers 'Tmdb\Laravel\TmdbServiceProvider', )
Then publish the configuration file:
php artisan vendor:publish --provider="Tmdb\Laravel\TmdbServiceProvider"
Next you can modify the generated configuration file tmdb.php accordingly.
That's all! Fire away!
Usage
We can choose to either use the Tmdb Facade, or to use dependency injection.
Development
Run the package quality checks locally with Composer scripts:
composer test
composer phpstan
Facade example
The example below shows how you can use the Tmdb facade.
If you don't want to keep adding the use Tmdb\Laravel\Facades\Tmdb; statement in your files, then you can also add the facade as an alias in config/app.php file.
use Tmdb\Laravel\Facades\Tmdb; class MoviesController { function show($id) { // returns information of a movie return Tmdb::getMoviesApi()->getMovie($id); } }
Dependency injection example
use Tmdb\Repository\MovieRepository; class MoviesController { private $movies; function __construct(MovieRepository $movies) { $this->movies = $movies; } function index() { // returns information of a movie return $this->movies->getPopular(); } }
Listening to events
We can easily listen to events that are dispatched using the Laravel event dispatcher that we're familiar with. The following example listens to any request that is made and logs a message.
use Event; use Illuminate\Support\Facades\Log; use Tmdb\Event\RequestEvent; Event::listen(RequestEvent::class, function (RequestEvent $event) { Log::info("A request was made to TMDB"); // do stuff with $event });
You can also register the same listener in your application's EventServiceProvider.
Image helper
You can easily use the ImageHelper by using dependency injection. The following example shows how to show the poster image of the 20 most popular movies.
namespace App\Http\Controllers; use Tmdb\Helper\ImageHelper; use Tmdb\Repository\MovieRepository; class WelcomeController extends Controller { private $movies; private $helper; public function __construct(MovieRepository $movies, ImageHelper $helper) { $this->movies = $movies; $this->helper = $helper; } /** * Show the application welcome screen to the user. * * @return Response */ public function index() { $popular = $this->movies->getPopular(); foreach ($popular as $movie) { $image = $movie->getPosterImage(); echo ($this->helper->getHtml($image, 'w154', 260, 420)); } } }
The Configuration used by the Tmdb\Helper\ImageHelper is automatically loaded by the IoC container.
Customizing outgoing requests
You can customize outgoing requests by listening for BeforeRequestEvent in one of your application's service providers.
namespace App\Providers; use Event; use Illuminate\Support\ServiceProvider; use Tmdb\Event\BeforeRequestEvent; class TmdbServiceProvider extends ServiceProvider { /** * Customize TMDB requests before they are sent. * * @return void */ public function boot() { Event::listen(BeforeRequestEvent::class, function (BeforeRequestEvent $event) { $request = $event->getRequest()->withHeader('Accept-Language', 'nl-NL'); $event->setRequest($request); }); } /** * Register services * @return void */ public function register() { // register any services that you need } }
For all all other interactions take a look at php-tmdb/api.