84 lines
2.0 KiB
PHP
84 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Interaction;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\StoreReportRequest;
|
|
use App\Models\Deal;
|
|
use App\Models\Report;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class ReportController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(StoreReportRequest $request, Deal $deal)
|
|
{
|
|
$data = $request->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)
|
|
{
|
|
//
|
|
}
|
|
}
|