gitresethard / tmdb-laravel
Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the php-tmdb/api library.
Fund package maintenance!
Requires
- php: ^8.4
- guzzlehttp/guzzle: ^7.9
- illuminate/contracts: ^11.0||^12.0
- nyholm/psr7: ^1.8
- php-http/guzzle7-adapter: ^1.1
- php-tmdb/api: 4.1.x-dev
- spatie/laravel-package-tools: ^1.93
- symfony/event-dispatcher: ^7.0||^8.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.27
- nunomaduro/collision: ^8.9
- orchestra/testbench: ^9.0||^10.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
README
A modern Laravel 11/12 package for the TMDB (The Movie Database) API. Built on top of php-tmdb/api v4 with full PSR compliance.
Requirements
- PHP 8.4+
- Laravel 11.x or 12.x
Installation
composer require gitresethard/tmdb-laravel
Add your TMDB API token to .env:
TMDB_API_TOKEN=your-tmdb-api-token-here
Publish the config file (optional):
php artisan vendor:publish --tag="tmdb-laravel-config"
Verify your setup:
php artisan tmdb:test
Configuration
All configuration is in config/tmdb-laravel.php. Key options:
| Key | Env Variable | Default | Description |
|---|---|---|---|
api_token |
TMDB_API_TOKEN |
'' |
Your TMDB API key or Bearer token |
bearer |
TMDB_BEARER |
false |
Set true for v4 Bearer/Read Access Token |
language |
TMDB_LANGUAGE |
en-US |
Default language filter |
region |
TMDB_REGION |
null |
Default region filter |
include_adult |
TMDB_INCLUDE_ADULT |
false |
Include adult content |
cache.enabled |
TMDB_CACHE_ENABLED |
true |
Enable response caching |
logging.enabled |
TMDB_LOG_ENABLED |
false |
Enable request/response logging |
Usage
Facade
use GitResetHard\TmdbLaravel\Facades\TmdbLaravel; // Get a movie by ID $movie = TmdbLaravel::getMovie(550); // Fight Club echo $movie->getTitle(); // Popular movies $popular = TmdbLaravel::getPopularMovies(); // Search $results = TmdbLaravel::searchMovies('Inception'); // TV shows $show = TmdbLaravel::getTvShow(1399); // Breaking Bad // People $person = TmdbLaravel::getPerson(287);
Dependency Injection
use GitResetHard\TmdbLaravel\TmdbLaravel; class MovieController extends Controller { public function __construct( private readonly TmdbLaravel $tmdb, ) {} public function show(int $id) { $movie = $this->tmdb->getMovie($id); return view('movies.show', compact('movie')); } public function index() { $popular = $this->tmdb->getPopularMovies(); return view('movies.index', compact('popular')); } }
Using Repositories Directly
For more control, access the underlying php-tmdb/api repositories:
use GitResetHard\TmdbLaravel\Facades\TmdbLaravel; // Movie repository $movieRepo = TmdbLaravel::getMovieRepository(); $credits = $movieRepo->getCredits(550); $similar = $movieRepo->getSimilar(550); $videos = $movieRepo->getVideos(550); // TV repository $tvRepo = TmdbLaravel::getTvRepository(); $season = TmdbLaravel::getTvSeasonRepository(); $episode = TmdbLaravel::getTvEpisodeRepository(); // Search repository $searchRepo = TmdbLaravel::getSearchRepository(); $results = $searchRepo->searchMulti('Breaking Bad'); // Discover repository $discoverRepo = TmdbLaravel::getDiscoverRepository(); // Genre repository $genreRepo = TmdbLaravel::getGenreRepository();
Using the Raw Client
Access the underlying Tmdb\Client for full API access:
use GitResetHard\TmdbLaravel\Facades\TmdbLaravel; $client = TmdbLaravel::getClient(); // Raw API calls $movieData = $client->getMoviesApi()->getMovie(550); $tvData = $client->getTvApi()->getTvshow(1399);
Image Helper
use GitResetHard\TmdbLaravel\Facades\TmdbLaravel; $movie = TmdbLaravel::getMovie(550); $imageHelper = TmdbLaravel::getImageHelper(); $posterImage = $movie->getPosterImage(); echo $imageHelper->getHtml($posterImage, 'w342', 342, 513);
Available Shortcut Methods
| Method | Description |
|---|---|
getMovie($id) |
Get movie details |
getPopularMovies() |
Popular movies |
getTopRatedMovies() |
Top rated movies |
getNowPlayingMovies() |
Now playing movies |
getUpcomingMovies() |
Upcoming movies |
getTvShow($id) |
Get TV show details |
getPopularTv() |
Popular TV shows |
getTopRatedTv() |
Top rated TV shows |
getPerson($id) |
Get person details |
searchMovies($query) |
Search movies |
searchTv($query) |
Search TV shows |
searchPeople($query) |
Search people |
searchMulti($query) |
Search all types |
Available Repositories
Access any repository via get{Name}Repository():
Movie, Tv, TvSeason, TvEpisode, Search, People, Collection, Company, Configuration, Discover, Find, Genre, Network, Keyword, Review, Certification, Changes, List, Account
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
- GitResetHard
- php-tmdb/api by Michael Roterman
- All Contributors
License
The MIT License (MIT). Please see License File for more information.