feat: hunts params
This commit is contained in:
parent
a75fd5c93c
commit
b6c756c30a
|
|
@ -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());
|
||||
|
|
|
|||
Loading…
Reference in New Issue