dariusiii/tmdb-laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the wtfzdotnet/php-tmdb-api library.
21,307 18
Install
composer require dariusiii/tmdb-laravel
Latest Version:13.0
PHP:>=8.3
License:MIT
Last Updated:Mar 20, 2026
Links: GitHub  ·  Packagist
Maintainer: DariusIII

Laravel Package for TMDB API Wrapper

License Build Status Code Coverage

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.

Latest Stable Version Latest Unstable Version Total Downloads

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.

Related Packages

wtfzdotnet/tmdb-package

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the...

492 160
php-tmdb/laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the...

53,315 160
bhutanio/movietvdb

Movie and TV Database API, Scrapes data from themoviedb.org (tmdb), thetvdb.com...

755 16
skizu/simpleapi

Simple api wrapper with easy caching and throttling

170 2
solvire/php-hypermedia-api

PHP Hypermedia Enabled API Wrapper for HTTP REST

61 14