123movies-seo/app/Supports/Traits/TopContent.php

70 lines
2.2 KiB
PHP

<?php
namespace App\Supports\Traits;
use App\Services\ApiClient;
use App\Services\TmdbClient;
use App\Supports\Traits\Helpers;
use Carbon\Carbon;
use Carbon\CarbonInterval;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Cache;
trait TopContent {
use Helpers;
public function getTopContent(TmdbClient $tmdb, ApiClient $api)
{
return Cache::remember('top_content', 3600, function() use($tmdb, $api) {
$trending = self::formatApiResponse($api->getTrendingMovies(1, 20), false, [], 20)['data'];
$popular = $this->formatTmdbResponse($tmdb->getPopularMovies(1), false, [], 20)['data'];
$trending_shows = self::formatApiResponse($api->getTrendingShows(1, 20), false, [], 20)['data'];
$popular_shows = $this->formatTmdbResponse($tmdb->getPopularShows(1), false, [], 20)['data'];
return [
'movies' => [
'col1' =>
array_map(function($item) {
return [
'title' => $item['title'],
'slug' => $item['slug'],
'id' => $item['id'],
];
}, $trending),
'col2' => array_map(function($item) {
return [
'title' => $item['title'],
'slug' => $item['slug'],
'id' => $item['id'],
];
}, $popular)
],
'shows' => [
'col1' =>
array_map(function($item) {
return [
'title' => $item['title'],
'slug' => $item['slug'],
'id' => $item['id'],
];
}, $trending_shows),
'col2' => array_map(function($item) {
return [
'title' => $item['title'],
'slug' => $item['slug'],
'id' => $item['id'],
];
}, $popular_shows)
]
];
});
}
}