pvguerra / laravel-trakt
Integrate Laravel with Trakt API
Requires
- php: ^8.3
- guzzlehttp/guzzle: ^7.0
- illuminate/contracts: ^11.0
- spatie/laravel-package-tools: ^1.16.4
Requires (Dev)
- larastan/larastan: ^2.9
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^9.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^10.5
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2025-05-09 14:43:26 UTC
README
Integrate Laravel with Trakt API
The whole package was developed following the official Trakt API Documentation.
Installation
You can install the package via composer:
composer require pvguerra/laravel-trakt
You can publish the config file with:
php artisan vendor:publish --tag="trakt-config"
This is the contents of the published config file:
return [ 'api_url' => env('TRAKT_API_URL'), 'client_id' => env('TRAKT_CLIENT_ID'), 'client_secret' => env('TRAKT_CLIENT_SECRET'), 'headers' => [ 'Content-type' => 'application/json', 'trakt-api-version' => env('TRAKT_API_VERSION', '2'), 'trakt-api-key' => env('TRAKT_CLIENT_ID'), ], 'redirect_url' => env('TRAKT_REDIRECT_URL'), 'staging_api_url' => env('STAGING_TRAKT_API_URL'), 'staging_client_id' => env('STAGING_TRAKT_CLIENT_ID'), 'staging_client_secret' => env('STAGING_TRAKT_CLIENT_SECRET'), 'staging_headers' => [ 'Content-type' => 'application/json', 'trakt-api-version' => env('TRAKT_API_VERSION', '2'), 'trakt-api-key' => env('STAGING_TRAKT_CLIENT_ID'), ], ];
Usage
If you don't have a Trakt client ID, you'll need to create a new API app. Then you'll get all you need to fill the environment variables for configuration.
Movies
use Pvguerra\LaravelTrakt\TraktMovie; $traktMovie = new TraktMovie(); return $traktMovie->get('the-batman-2022');
TV Shows
use Pvguerra\LaravelTrakt\TraktShow; $traktShow = new TraktShow(); return $traktShow->popular();
Auth Required
Some endpoints are auth required, for these you'll need an API Token. At this point I strongly recommend Trakt Socialite Providers since it extends Laravel Socialite and works flawlessly.
Example:
// web.php Route::get('auth/redirect', [OAuthController::class, 'redirect'])->name('trakt.auth'); Route::get('auth/callback', [OAuthController::class, 'callback'])->name('trakt.callback'); // authController.php use Laravel\Socialite\Facades\Socialite; // Redirecting the user to the OAuth provider. public function redirect() { return Socialite::driver('trakt')->redirect(); } // Receiving the callback from the provider after authentication. public function callback() { $socialiteUser = Socialite::driver('trakt')->user(); //... }
Then with the authenticated user:
use Pvguerra\LaravelTrakt\TraktUser; $user = auth()->user(); $traktUser = new TraktUser($user->token); return $traktUser->collection($user->trakt_id, 'movies');
Documentation
Full documentation will be available soon.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Pull requests are welcome!
Credits
License
The MIT License (MIT). Please see License File for more information.