2025-02-10 01:58:12 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
2026-03-08 15:10:53 +02:00
|
|
|
use App\Models\Genre;
|
2025-02-16 21:11:07 +02:00
|
|
|
use App\Models\Season;
|
2025-02-10 01:58:12 +02:00
|
|
|
use App\Models\Show;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
|
|
class ShowController extends Controller
|
|
|
|
|
{
|
2026-03-08 15:10:53 +02:00
|
|
|
public function index(Request $request)
|
2025-02-10 01:58:12 +02:00
|
|
|
{
|
2026-03-08 15:10:53 +02:00
|
|
|
$query = Show::query();
|
2025-02-10 01:58:12 +02:00
|
|
|
|
2026-03-08 15:10:53 +02:00
|
|
|
// Search by title
|
|
|
|
|
if ($request->filled('title')) {
|
|
|
|
|
$query->where('name', 'LIKE', '%' . $request->title . '%');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter by genre
|
|
|
|
|
if ($request->filled('genre')) {
|
|
|
|
|
$query->whereHas('genres', function ($q) use ($request) {
|
|
|
|
|
$q->where('genre_id', $request->genre);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter by actor
|
|
|
|
|
if ($request->filled('actor')) {
|
|
|
|
|
$query->whereHas('castList', function ($q) use ($request) {
|
|
|
|
|
$q->where('person_id', $request->actor);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter by network
|
|
|
|
|
if ($request->filled('network')) {
|
|
|
|
|
$query->whereHas('networks', function ($q) use ($request) {
|
|
|
|
|
$q->where('network_id', $request->network);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter by rating
|
|
|
|
|
if ($request->filled('rating_min')) {
|
|
|
|
|
$query->where('vote_average', '>=', $request->rating_min);
|
|
|
|
|
}
|
|
|
|
|
if ($request->filled('rating_max')) {
|
|
|
|
|
$query->where('vote_average', '<=', $request->rating_max);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter by first air year
|
|
|
|
|
if ($request->filled('year_min')) {
|
|
|
|
|
$query->whereYear('first_air_date', '>=', $request->year_min);
|
|
|
|
|
}
|
|
|
|
|
if ($request->filled('year_max')) {
|
|
|
|
|
$query->whereYear('first_air_date', '<=', $request->year_max);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter by status
|
|
|
|
|
if ($request->filled('status')) {
|
|
|
|
|
$query->where('status', $request->status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sorting
|
|
|
|
|
$sortBy = $request->get('sort_by', 'first_air_date');
|
|
|
|
|
$sortOrder = $request->get('sort_order', 'DESC');
|
|
|
|
|
|
|
|
|
|
$allowedSorts = ['name', 'first_air_date', 'vote_average', 'vote_count'];
|
|
|
|
|
if (in_array($sortBy, $allowedSorts)) {
|
|
|
|
|
$query->orderBy($sortBy, $sortOrder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$shows = $query->paginate(48)->appends($request->except('page'));
|
|
|
|
|
|
|
|
|
|
// Get all genres for filter dropdowns (only TV show genres)
|
|
|
|
|
$genres = Genre::where('type', Genre::TYPE_SHOW)->orderBy('name')->get();
|
|
|
|
|
|
|
|
|
|
// Get all networks for filter dropdown
|
|
|
|
|
$networks = \App\Models\Network::orderBy('name')->get();
|
|
|
|
|
|
|
|
|
|
return view('show.index', compact('shows', 'genres', 'networks'));
|
2025-02-10 01:58:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function show(string $slug)
|
|
|
|
|
{
|
|
|
|
|
$show = Show::with('posters', 'backdrops', 'externalIds', 'networks', 'genres', 'productionCompanies')->where('slug', $slug)->first();
|
|
|
|
|
|
|
|
|
|
$comments = [];
|
|
|
|
|
|
2025-02-16 21:11:07 +02:00
|
|
|
$seasons = Season::where('show_id', $show->id)->orderBy('season_number', 'ASC')->get();
|
|
|
|
|
|
|
|
|
|
return view('show.show', compact('show', 'comments', 'seasons'));
|
2025-02-10 01:58:12 +02:00
|
|
|
}
|
2025-08-07 23:01:58 +03:00
|
|
|
|
|
|
|
|
public function season(string $slug, int $seasonNumber)
|
|
|
|
|
{
|
2025-09-06 14:41:10 +03:00
|
|
|
$show = Show::with('posters', 'backdrops', 'externalIds', 'networks', 'genres', 'productionCompanies')->where('slug', $slug)->first();
|
2025-08-07 23:01:58 +03:00
|
|
|
|
2025-09-06 14:41:10 +03:00
|
|
|
if (!$show) {
|
|
|
|
|
abort(404);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$seasons = Season::where('show_id', $show->id)->orderBy('season_number', 'ASC')->get();
|
|
|
|
|
$currentSeason = Season::where('show_id', $show->id)->where('season_number', $seasonNumber)->first();
|
|
|
|
|
|
|
|
|
|
if (!$currentSeason) {
|
|
|
|
|
abort(404);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$episodes = \App\Models\Episode::where('show_id', $show->id)
|
|
|
|
|
->where('season_id', $currentSeason->id)
|
|
|
|
|
->orderBy('episode_number', 'ASC')
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
$comments = [];
|
|
|
|
|
|
|
|
|
|
return view('show.season', compact('show', 'seasons', 'currentSeason', 'episodes', 'comments'));
|
2025-08-07 23:01:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function episode(string $slug, int $seasonNumber, int $episodeNumber)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2025-02-10 01:58:12 +02:00
|
|
|
}
|