All Projects → Astrotomic → laravel-tmdb

Astrotomic / laravel-tmdb

Licence: MIT license
Interact with TMDB data in your Laravel application.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-tmdb

TVToday
iOS TV Shows app with TMDb Api. RxSwift, MVVM, Clean Architecture. Tuist + Swift Package Manager
Stars: ✭ 27 (+8%)
Mutual labels:  themoviedb, tmdb, tmdb-api, themoviedb-api
AndroidTVMovieParadise
Movie Paradise is an Android TV 📺 app. ExoPlayer, Dagger 2, RxJava libraries are used.
Stars: ✭ 68 (+172%)
Mutual labels:  tmdb-api, movies-api, tmdb-movie
tmdb-api
This Kotlin Multiplatform library is for accessing the TMDB API to get movie and TV show content. Using for Android, iOS, and JS projects.
Stars: ✭ 31 (+24%)
Mutual labels:  tmdb, tmdb-api, tmdb-rest-api
TheMovieDatabaseSwiftWrapper
Swift wrapper for themoviedb.org api v3
Stars: ✭ 126 (+404%)
Mutual labels:  tmdb, tmdb-api, movies-api
Paging-3-Sample
This app is created as a sample app which loads movies from Tmdb api and uses Paging 3 library to show it in a Recycler view.
Stars: ✭ 96 (+284%)
Mutual labels:  tmdb, tmdb-api
movies
Real world isomorphic application for movies search, based on Webpack 5 / Express / React 17 + Redux-Saga / Bootstrap 4.6 + CSS Modules / i18next / SSR
Stars: ✭ 20 (-20%)
Mutual labels:  tmdb, movies-api
laravel-cachable-attributes
Allows to cache attribute accessor values in an easy way.
Stars: ✭ 24 (-4%)
Mutual labels:  eloquent, treeware
MoviezApp
Simple iOS application that provides you with the latest movies in cinema.
Stars: ✭ 22 (-12%)
Mutual labels:  movie-database, movies-api
auto-movie-tagger
A Python script that auto tags and adds poster to mkv or mp4 movie files.
Stars: ✭ 49 (+96%)
Mutual labels:  tmdb, tmdb-api
tmdb bot
IMDB Telegram bot clone using TMDB to get info about movies and TV shows.
Stars: ✭ 22 (-12%)
Mutual labels:  themoviedb, themoviedb-api
WatchSomething
Project that uses an API to list movies and tv shows that are latest, popular, top rated & on air.
Stars: ✭ 11 (-56%)
Mutual labels:  themoviedb, themoviedb-api
flask-movie-app
A watch-list app with Flask using the TMDB API with CRUD and user authentication.
Stars: ✭ 26 (+4%)
Mutual labels:  tmdb, tmdb-api
MovieCards
React App that uses TMDb API to display movie data. Try it out! ->
Stars: ✭ 38 (+52%)
Mutual labels:  tmdb, tmdb-api
PopMovies
Aplicativo em Android para organização dos seus filmes favoritos.
Stars: ✭ 41 (+64%)
Mutual labels:  themoviedb, tmdb
ksoftapi.py
Official API Wrapper for KSoft.Si API
Stars: ✭ 31 (+24%)
Mutual labels:  api-client
nyxx
Wrapper around Discord API for Dart
Stars: ✭ 217 (+768%)
Mutual labels:  api-client
ebics-java-client
Java open source EBICS client - Support for French, German and Swiss banks
Stars: ✭ 30 (+20%)
Mutual labels:  api-client
private-packagist-api-client
Private Packagist API Client
Stars: ✭ 28 (+12%)
Mutual labels:  api-client
twinfield
PHP 7.3+ Library for using the Twinfield API.
Stars: ✭ 28 (+12%)
Mutual labels:  api-client
buttercms-go
Golang CMS and blog engine https://buttercms.com
Stars: ✭ 37 (+48%)
Mutual labels:  api-client

Laravel TMDB

Latest Version MIT License Offset Earth Larabelles

GitHub Workflow Status GitHub Workflow Status

Total Downloads Trees Carbon

Installation

composer require astrotomic/laravel-tmdb
php artisan vendor:publish --tag=tmdb-migrations

Configuration

Add your TMDB API v4 Token to the config/services.php file.

config/services.php

return [
    // ...
    
    'tmdb' => [
        'token' => env('TMDB_TOKEN'),
    ],

    // ...
];

After that you can configure your language and region to be used by the package for some of the API requests. By default we use app()->getLocale() for the language and a hardcoded US region. It's recommended to call this in your AppServiceProvider but you can call the methods from everywhere in your codecase. In case you want to run a specific callback with a region or language without changing the globally used ones you can use the with methods. These will set the region or language to teh given one for the callback and automatically restore the old one after running the callback.

use Astrotomic\Tmdb\Facades\Tmdb;

Tmdb::useLanguage('de');
Tmdb::useRegion('DE');

Tmdb::withLanguage('de', fn() => \Astrotomic\Tmdb\Models\Movie::find(335983));
Tmdb::withRegion('DE', fn() => \Astrotomic\Tmdb\Models\Movie::upcoming(20));

Usage

Models

The easiest and most feature complete way to use the package are the provided models. They come with custom query builders which do API calls if the requested model isn't found in your local database. This only applies to the find() and sometimes the all() methods. So if you only want to query your database, you can do so by using whereKey()->first() for example.

use Astrotomic\Tmdb\Models\Movie;

Movie::find(335983);
Movie::findMany([335983, 575788]);
Movie::findOrFail(335983);

It's recommended to prepare two "static" models to save future calls by calling their all() method once. This will do one HTTP call per model and save multiple HTTP calls in the future.

use Astrotomic\Tmdb\Models\MovieGenre;
use Astrotomic\Tmdb\Models\TvGenre;
use Astrotomic\Tmdb\Models\WatchProvider;

MovieGenre::all();
TvGenre::all();
WatchProvider::all();

Most models use spatie/laravel-translatable with a slightly customized translate() method. This will automatically load a missing translation if you request it.

use Astrotomic\Tmdb\Models\Movie;

app()->setLocale('en');
$movie = Movie::find(335983);
$movie->translate('title', 'en'); // get title from DB
$movie->translate('title', 'de'); // get and persist title from API

If you want to update the data in your database you can call the updateFromTmdb() method on any of the models. This should be done a console command or queue job as it will do a lot of HTTP requests and can take few minutes per movie.

use Astrotomic\Tmdb\Models\Movie;

Movie::eachById(static function(Movie $movie): void {
    $movie->updateFromTmdb('de', ['credits']);
});

Movie

First of all you can also find() a movie with additional relations and they will also be queried from the API. To do so you only have to call the with() method on the query before you call any of the find() methods.

use Astrotomic\Tmdb\Models\Movie;

Movie::with('genres')->find(335983);
Movie::with('credits')->find(335983);
Movie::with('cast')->find(335983);
Movie::with('crew')->find(335983);

There are some methods that do a HTTP call every single time. And if they accept a $limit argument they automically call each page till the amount of IDs is found. You have to provide an explicit argument, in case you use null it will call every page. This can result in several thousands of requests - so it's more recommended to provide a serious number.

use Astrotomic\Tmdb\Models\Movie;

Movie::popular(20);
Movie::upcoming(20);
Movie::toprated(20);
Movie::trending(20);
Movie::nowPlaying(20);

Movie::findOrFail(335983)->recommendations(20);
Movie::findOrFail(335983)->similars(20);

You can also get all watch providers (powered by JustWatch) for a given movie. These can be filtered/limited to a given region and/or type.

use Astrotomic\Tmdb\Models\Movie;
use Astrotomic\Tmdb\Enums\WatchProviderType;

Movie::findOrFail(335983)->watchProviders();
Movie::findOrFail(335983)->watchProviders('DE');
Movie::findOrFail(335983)->watchProviders(null, WatchProviderType::FLATRATE());
Movie::findOrFail(335983)->watchProviders('DE', WatchProviderType::FLATRATE());

And there are some helper methods on the movie model to easier work with some attributes.

use Astrotomic\Tmdb\Models\Movie;

Movie::findOrFail(335983)->runtime();
Movie::findOrFail(335983)->poster();
Movie::findOrFail(335983)->backdrop();

Person

The person model has the same base model as the movie and general method API.

use Astrotomic\Tmdb\Models\Person;

Person::with('movie_credits')->find(6384);
Person::trending(20);
Person::findOrFail(6384)->profile();

Images

There are some helper classes to generate image URLs for you with correct aspect-ratio. Models with image path attributes have a shortcut method which returns an instance of that image class.

use Astrotomic\Tmdb\Models\Movie;

Movie::find(335983)->poster();
Movie::find(335983)->backdrop();

These image helpers will render a <img/> tag if you echo them in your Blade templates. In case they are casted to string they will return the image URL or a fallback one. You can also call url() or fallback() to get one or the other URL and use them however you want.

Requests

The models use OOP request classes which you can also use your own. These aren't the primary usage API but in case you need them, feel free to use.

use Astrotomic\Tmdb\Requests\Movie\Details;

Details::request(335983)->send()->json();

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details. You could also be interested in CODE OF CONDUCT.

Security

If you discover any security related issues, please check SECURITY for steps to report it.

Credits

License

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

Treeware

You're free to use this package, but if it makes it to your production environment I would highly appreciate you buying the world a tree.

It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to plant trees. If you contribute to my forest you’ll be creating employment for local families and restoring wildlife habitats.

You can buy trees at ecologi.com/astrotomic

Read more about Treeware at treeware.earth

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].