123movies-seo/app/Http/Controllers/HomeController.php

119 lines
4.4 KiB
PHP
Raw Normal View History

2024-08-24 23:08:42 +03:00
<?php
namespace App\Http\Controllers;
use App\Http\Requests\SearchRequest;
2024-08-27 18:46:07 +03:00
use App\Http\Resources\MoreTitles;
2024-08-24 23:08:42 +03:00
use App\Models\News;
use App\Services\ApiClient;
use App\Services\TmdbClient;
2024-08-27 18:46:07 +03:00
use DipeshSukhia\LaravelHtmlMinify\LaravelHtmlMinifyFacade;
2024-08-24 23:08:42 +03:00
use Illuminate\Http\Request;
use App\Supports\Traits\Helpers;
use Illuminate\Support\Str;
use App\Supports\Traits\CleanItems;
use App\Supports\Traits\TopContent;
2024-08-27 18:46:07 +03:00
use Route;
2024-08-24 23:08:42 +03:00
use stdClass;
use Symfony\Component\HttpFoundation\Response;
class HomeController extends Controller
{
use CleanItems, TopContent;
public function index(ApiClient $api, TmdbClient $tmdb)
{
$meta = [];
$meta['title'] = config('site.home.title');
$meta['description'] = Str::limit(config('site.home.description'), 150);
$meta['full_description'] = config('site.home.description');
$meta['keywords'] = config('site.home.keywords', false);
2024-08-28 01:03:34 +03:00
$meta['image'] = asset('images/cover.jpg');
2024-08-24 23:08:42 +03:00
$nowplaying = $this->formatTmdbResponse($tmdb->getNowPlayingMovies(1), false, [], 12)['data'];
$upcoming = $this->formatTmdbResponse($tmdb->getUpcomingMovies(1), false, [], 12)['data'];
$comingsoon = $this->formatTmdbResponse($tmdb->getComingSoonMovies(1), false, [], 6)['data'];
$airing = $this->formatTmdbResponse($tmdb->getAiringShows(1), false, [], 12)['data'];
2024-09-10 01:33:11 +03:00
$hero = $this->getHomeHeroSliderData($api->getTrendingMovies(1, 5), $tmdb);
2024-08-24 23:08:42 +03:00
// dd($hero);
$popular_movies = self::formatApiResponse($api->getPopularMovies(1, 12), false)['data'];
$popular_shows = self::formatApiResponse($api->getTrendingShows(1, 12), false, [], 12)['data'];
$trending_movies = self::formatApiResponse($api->getTrendingMovies(1, 12), false, [], 12)['data'];
$trending_shows = self::formatApiResponse($api->getTrendingShows(1, 12), false)['data'];
$recent_added = $trending_movies[4];
return view('home', compact('meta', 'hero', 'popular_movies', 'popular_shows', 'trending_movies', 'trending_shows', 'nowplaying', 'upcoming', 'comingsoon', 'airing', 'recent_added'));
}
public function homesearch()
{
$meta = [];
$meta['title'] = config('site.homesearch.title');
$meta['description'] = Str::limit(config('site.homesearch.description'), 150);
$meta['full_description'] = config('site.homesearch.description');
$meta['keywords'] = config('site.homesearch.keywords', false);
2024-08-28 01:03:34 +03:00
$meta['image'] = asset('images/cover.jpg');
2024-08-24 23:08:42 +03:00
$content = config('site.homesearch.content');
return view('homesearch', compact('meta', 'content'));
}
2024-09-25 07:40:46 +03:00
public function search(SearchRequest $request, ApiClient $api)
2024-08-24 23:08:42 +03:00
{
$query = $request->validated()['search'];
2024-08-27 18:46:07 +03:00
$page = $request->query('page', 1);
2024-09-25 07:40:46 +03:00
$results = $api->getSearch($query);
['data' => $data, 'pagination' => $pagination] = $this->formatApiSearchResponse($results);
2024-08-27 18:46:07 +03:00
$page_text = ($page > 1)
? sprintf(' - Page %s', $page)
: '';
2024-08-24 23:08:42 +03:00
$meta = [];
2024-08-27 18:46:07 +03:00
$meta['title'] = str(config('site.search.title'))->replace(['{QUERY}'], $query)->replace(['{PAGE}'], $page_text)->apa();
2024-08-28 21:02:13 +03:00
$meta['page_title'] = str(config('site.search.page_title'))->replace(['{QUERY}'], $query)->replace(['{PAGE}'], $page_text)->apa();
2024-08-27 18:46:07 +03:00
$meta['description'] = str(config('site.search.description'))->replace(['{QUERY}'], $query)->replace(['{PAGE}'], $page_text);
2024-08-24 23:08:42 +03:00
$meta['keywords'] = config('site.search.keywords', false);
2024-08-28 01:03:34 +03:00
$meta['image'] = asset('images/cover.jpg');
2024-08-27 18:46:07 +03:00
$meta['route'] = Route::current();
// dd($meta['route']);
// $query = str($query)->apa();
2024-08-24 23:08:42 +03:00
// sleep(2);
2024-08-27 18:46:07 +03:00
return view('search', compact('data', 'pagination', 'meta', 'query'));
}
2024-09-25 07:40:46 +03:00
public function search_more(SearchRequest $request, ApiClient $api)
2024-08-27 18:46:07 +03:00
{
$query = $request->validated()['search'];
$page = $request->validated()['page'];
2024-09-25 07:40:46 +03:00
$results = $this->formatApiSearchResponse($api->getSearch($query), $page);
2024-08-27 18:46:07 +03:00
// dd($results);
$items = MoreTitles::collection($results['data']);
$has_more_pages = $results['pagination']->hasMorePages();
$current_page = $results['pagination']->currentPage();
$html = LaravelHtmlMinifyFacade::htmlMinify(view('components.more_titles', compact('items'))->render());
return response()->json(compact('current_page', 'has_more_pages', 'html'));
2024-08-24 23:08:42 +03:00
}
}