shows advanced search and filter

This commit is contained in:
Doar Mihai
2026-03-08 15:10:53 +02:00
parent f8c1324e11
commit a094c28567
3 changed files with 209 additions and 5 deletions
+68 -3
View File
@@ -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)
@@ -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'];