json($hunts); } /** * Store a newly created resource in storage. */ public function store(Request $request) { $validated = $request->validate([ 'partner_id' => 'required|string', 'title' => 'required|string', 'slug' => 'required|string|unique:hunts,slug', 'description' => 'nullable|string', 'status' => 'required|string', 'difficulty' => 'required|string', 'city' => 'required|string', 'latitude' => 'nullable|numeric', 'longitude' => 'nullable|numeric', 'is_public' => 'boolean', 'estimated_duration_min' => 'nullable|integer', 'start_at' => 'nullable|date', 'end_at' => 'nullable|date', 'image' => 'nullable|string', 'creator_id' => 'nullable|exists:users,id', ]); $hunt = Hunts::create($validated); return response()->json($hunt, 201); } /** * Display the specified resource. */ public function show($id) { $hunt = Hunts::find($id); if (!$hunt) { return response()->json(['message' => 'Hunt not found'], 404); } return response()->json($hunt); } /** * Update the specified resource in storage. */ public function update(Request $request, $id) { $hunt = Hunts::find($id); if (!$hunt) { return response()->json(['message' => 'Hunt not found'], 404); } $validated = $request->validate([ 'partner_id' => 'sometimes|string', 'title' => 'sometimes|string', 'slug' => 'sometimes|string|unique:hunts,slug,' . $id, 'description' => 'nullable|string', 'status' => 'sometimes|string', 'difficulty' => 'sometimes|string', 'city' => 'sometimes|string', 'latitude' => 'nullable|numeric', 'longitude' => 'nullable|numeric', 'is_public' => 'boolean', 'estimated_duration_min' => 'nullable|integer', 'start_at' => 'nullable|date', 'end_at' => 'nullable|date', 'image' => 'nullable|string', 'creator_id' => 'nullable|exists:users,id', ]); $hunt->update($validated); return response()->json($hunt); } /** * Remove the specified resource from storage. */ public function destroy($id) { $hunt = Hunts::find($id); if (!$hunt) { return response()->json(['message' => 'Hunt not found'], 404); } $hunt->delete(); return response()->json(['message' => 'Hunt deleted successfully']); } }