61 lines
2.4 KiB
PHP
61 lines
2.4 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
use App\Http\Requests\MorePersonCastRequest;
|
||
|
use DipeshSukhia\LaravelHtmlMinify\LaravelHtmlMinifyFacade;
|
||
|
use Illuminate\Http\JsonResponse;
|
||
|
use Illuminate\Http\Request;
|
||
|
use App\Services\ApiClient;
|
||
|
use App\Services\TmdbClient;
|
||
|
use App\Supports\Traits\CleanItems;
|
||
|
use App\Supports\SchemaBuilder;
|
||
|
use App\Supports\Traits\Helpers;
|
||
|
use App\Supports\Traits\TopContent;
|
||
|
use Route;
|
||
|
|
||
|
class PeopleController extends Controller
|
||
|
{
|
||
|
use CleanItems;
|
||
|
|
||
|
public function index(TmdbClient $tmdbClient, int $id, string $slug) {
|
||
|
$results = $tmdbClient->getPerson($id);
|
||
|
$page = request()->query('page', 1);
|
||
|
['data' => $data, 'pagination' => $pagination, 'name' => $name] = $this->formatTmdbPersonResponse($results, $page);
|
||
|
$page_text = ($page > 1)
|
||
|
? sprintf(' - Page %s', $page)
|
||
|
: '';
|
||
|
// dd($pagination);
|
||
|
$data = $pagination->items();
|
||
|
|
||
|
$meta = [];
|
||
|
$meta['title'] = str(config('site.people.cast.title'))->replace(['{NAME}'], $name)->replace(['{PAGE}'], $page_text)->apa();
|
||
|
$meta['page_title'] = str(config('site.people.cast.page_title'))->replace(['{NAME}'], $name)->replace(['{PAGE}'], $page_text)->apa();
|
||
|
$meta['description'] = str(config('site.people.cast.description'))->replace(['{NAME}'], $name)->replace(['{PAGE}'], $page_text);
|
||
|
$meta['keywords'] = config('site.people.cast.keywords', false);
|
||
|
$meta['image'] = asset('images/cover.jpg');
|
||
|
$meta['route'] = Route::current();
|
||
|
// dd($meta['route']);
|
||
|
|
||
|
// $query = str($query)->apa();
|
||
|
|
||
|
// sleep(2);
|
||
|
return view('list', compact('data', 'pagination', 'meta', 'id'));
|
||
|
|
||
|
}
|
||
|
public function more(TmdbClient $tmdbClient, MorePersonCastRequest $request):JsonResponse {
|
||
|
$results = $tmdbClient->getPerson($request->validated()['person_id']);
|
||
|
$page = request()->query('page', 1);
|
||
|
['data' => $data, 'pagination' => $pagination, 'name' => $name] = $this->formatTmdbPersonResponse($results, $request->validated()['page']);
|
||
|
|
||
|
$items = $pagination->items();
|
||
|
|
||
|
|
||
|
$has_more_pages = $pagination->hasMorePages();
|
||
|
$current_page = $pagination->currentPage();
|
||
|
$html = LaravelHtmlMinifyFacade::htmlMinify(view('components.more_titles', compact('items'))->render());
|
||
|
|
||
|
return response()->json(compact('current_page', 'has_more_pages', 'html'));
|
||
|
}
|
||
|
}
|