feat: hunts params

This commit is contained in:
Leon 2026-01-05 12:12:09 +01:00
parent a75fd5c93c
commit b6c756c30a
1 changed files with 16 additions and 2 deletions

View File

@ -10,10 +10,24 @@ class HuntsController extends Controller
/** /**
* Display a listing of the resource. * Display a listing of the resource.
*/ */
public function index() public function index(Request $request)
{ {
try { 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); return response()->json($hunts);
} catch (\Exception $e) { } catch (\Exception $e) {
\Illuminate\Support\Facades\Log::error('Error fetching hunts: ' . $e->getMessage()); \Illuminate\Support\Facades\Log::error('Error fetching hunts: ' . $e->getMessage());