From a094c2856789198b850f72b5f1ef9e0e603fff34 Mon Sep 17 00:00:00 2001 From: Doar Mihai Date: Sun, 8 Mar 2026 15:10:53 +0200 Subject: [PATCH] shows advanced search and filter --- app/Http/Controllers/ShowController.php | 71 ++++++++- .../MediaProcessing/ShowProcessingService.php | 6 +- resources/views/show/index.blade.php | 137 +++++++++++++++++- 3 files changed, 209 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/ShowController.php b/app/Http/Controllers/ShowController.php index a7e0220..16da866 100644 --- a/app/Http/Controllers/ShowController.php +++ b/app/Http/Controllers/ShowController.php @@ -2,17 +2,82 @@ namespace App\Http\Controllers; +use App\Models\Genre; use App\Models\Season; use App\Models\Show; use Illuminate\Http\Request; class ShowController extends Controller { - public function index() + public function index(Request $request) { - $shows = Show::paginate(48); + $query = Show::query(); - return view('show.index', compact('shows')); + // 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')); } public function show(string $slug) diff --git a/app/Service/MediaProcessing/ShowProcessingService.php b/app/Service/MediaProcessing/ShowProcessingService.php index 267e581..7d925c7 100644 --- a/app/Service/MediaProcessing/ShowProcessingService.php +++ b/app/Service/MediaProcessing/ShowProcessingService.php @@ -642,7 +642,11 @@ class ShowProcessingService implements ProcessingInterface if (!$episode) { $tmdbEpisode['tmdb_id'] = $tmdbEpisode['id']; $tmdbEpisode['slug'] = Str::slug($tmdbEpisode['name']); - $tmdbEpisode['tmdb_show_id'] = $tmdbEpisode['show_id']; + + if (isset($tmdbEpisode['show_id'])) { + $tmdbEpisode['tmdb_show_id'] = $tmdbEpisode['show_id']; + } + $tmdbEpisode['season_id'] = $season->id; // $tmdbEpisode['crew'] = $tmdbEpisode['crew']; // $tmdbEpisode['guest_stars'] = $tmdbEpisode['guest_stars']; diff --git a/resources/views/show/index.blade.php b/resources/views/show/index.blade.php index 2d61ec3..428f779 100644 --- a/resources/views/show/index.blade.php +++ b/resources/views/show/index.blade.php @@ -4,8 +4,143 @@
+ +
+
+
+ Advanced Search & Filters + +
+
+
+
+
+
+ +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ +
+ + to + +
+
+ + +
+ +
+ + to + +
+
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+
+ +
+ + + Clear All + +
+
+
+
+
+ +
-
Shows
+
+ TV Shows + @if(request()->hasAny(['title', 'genre', 'network', 'rating_min', 'rating_max', 'year_min', 'year_max', 'status'])) + Filtered + @endif + ({{ $shows->total() }} results) +
@foreach($shows as $show)