validated(); $data['user_id'] = Auth::id(); // Check if the user already reported the deal $alreadyReported = $deal->reports()->where('user_id', Auth::id())->first(); if ($alreadyReported) { return response()->json(['message' => 'You already reported this report'], 405); } try { DB::transaction(function () use ($data, $deal) { Report::unguard(); Report::create($data)->deals()->attach($deal); Report::reguard(); }); return response()->json(['message' => 'Report created'], 201); } catch (\Throwable $exception) { Log::error('Error creating report', [ 'user_id' => Auth::id(), 'deal_id' => $deal->id, 'error' => $exception->getMessage(), 'trace' => $exception->getTraceAsString(), ]); return response()->json(['message' => 'Error creating report'], 500); } } /** * Display the specified resource. */ public function show(Report $report) { // } /** * Update the specified resource in storage. */ public function update(Request $request, Report $report) { // } /** * Remove the specified resource from storage. */ public function destroy(Report $report) { // } }