diff --git a/app/Http/Controllers/HuntsController.php b/app/Http/Controllers/HuntsController.php index 8bcd69b..ecd4d1c 100644 --- a/app/Http/Controllers/HuntsController.php +++ b/app/Http/Controllers/HuntsController.php @@ -10,10 +10,24 @@ class HuntsController extends Controller /** * Display a listing of the resource. */ - public function index() + public function index(Request $request) { try { - $hunts = Hunts::with('participants:id,avatar_uri')->paginate(10); + $query = Hunts::with('participants:id,avatar_uri'); + + if ($request->boolean('participating')) { + $query->whereHas('participants', function ($q) { + $q->where('user_id', auth()->id()); + }); + } + + if ($request->boolean('active')) { + $now = now(); + $query->where('start_at', '<=', $now) + ->where('end_at', '>=', $now); + } + + $hunts = $query->paginate(10); return response()->json($hunts); } catch (\Exception $e) { \Illuminate\Support\Facades\Log::error('Error fetching hunts: ' . $e->getMessage());