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

92 lines
3.2 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests\SearchRequest;
use App\Models\News;
use App\Services\ApiClient;
use App\Services\TmdbClient;
use Illuminate\Http\Request;
use App\Supports\Traits\Helpers;
use Illuminate\Support\Str;
use App\Supports\Traits\CleanItems;
use App\Supports\Traits\TopContent;
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);
$meta['image'] = asset('images/custom-icon.png');
$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'];
$hero = $this->getHomeHeroSliderData($api->getTrendingMovies(1, 7), $tmdb);
// 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);
$meta['image'] = asset('images/custom-icon.png');
$content = config('site.homesearch.content');
return view('homesearch', compact('meta', 'content'));
}
public function search(SearchRequest $request, ApiClient $api, TmdbClient $tmdb)
{
$query = $request->validated()['search'];
$results = $tmdb->getSearch($query);
$data = $this->formatTmdbSearchResponse($results);
$meta = [];
$meta['title'] = config('site.search.title');
$meta['description'] = Str::replace(['{QUERY}'], $query, config('site.search.description'));
$meta['keywords'] = config('site.search.keywords', false);
$meta['image'] = asset('images/custom-icon.png');
$meta['page_title'] = 'Search Results for: '. $query;
// sleep(2);
return view('search', compact('data', 'meta'));
}
}