在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):php-tmdb/laravel开源软件地址(OpenSource Url):https://github.com/php-tmdb/laravel开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Laravel Package for TMDB API WrapperA 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 Looking for maintainersWe are urgently looking for new mainteners of this library, we need someone that can steer this package in the right direction for the Laravel community, we do not currently have anybody on the InstallationInstall Composer
Add the following to your require block in
or just run the following command in your project:
ConfigurationAdd to your 'providers' => array(
// other service providers
'Tmdb\Laravel\TmdbServiceProvider',
) Then publish the configuration file: Laravel 4
Laravel 5
Next you can modify the generated configuration file That's all! Fire away! UsageWe can choose to either use the Facade exampleThe example below shows how you can use the use Tmdb\Laravel\Facades\Tmdb; // optional for Laravel ≥5.5
class MoviesController {
function show($id)
{
// returns information of a movie
return Tmdb::getMoviesApi()->getMovie($id);
}
} Dependency injection exampleuse 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 eventsWe 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 Log;
use Event;
use Tmdb\Event\TmdbEvents;
use Tmdb\Event\RequestEvent;
Event::listen(TmdbEvents::REQUEST, function(RequestEvent $event) {
Log::info("A request was made to TMDB");
// do stuff with $event
}); In Laravel 5 instead of using the Image helperYou can easily use the 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
Registering pluginsPlugins can be registered in a service provider using the namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Tmdb\HttpClient\Plugin\LanguageFilterPlugin;
class TmdbServiceProvider extends ServiceProvider {
/**
* Add a Dutch language filter to the Tmdb client
*
* @return void
*/
public function boot()
{
$plugin = new LanguageFilterPlugin('nl');
$client = $this->app->make('Tmdb\Client');
$client->getHttpClient()->addSubscriber($plugin);
}
/**
* 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. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论