some progress

This commit is contained in:
2025-09-20 16:47:41 +03:00
parent e650f3c1b2
commit 2228469bcb
65 changed files with 3382 additions and 311 deletions
@@ -0,0 +1,51 @@
<?php
namespace App\Http\Controllers;
use App\Models\Book;
use App\Models\SummaryReport;
use Illuminate\Http\Request;
class SummaryReportController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
/**
* Store a newly created summary report in storage.
*/
public function store(Request $request, Book $book)
{
$validated = $request->validate([
'reason' => 'required|string|max:100',
'details' => 'nullable|string|max:5000',
]);
// Try to prevent duplicate reports from the same user for the same book
$report = SummaryReport::firstOrCreate(
[
'user_id' => $request->user()->id,
'book_id' => $book->id,
],
[
'summary_id' => optional($book->summary)->id,
'reason' => $validated['reason'],
'details' => $validated['details'] ?? null,
'status' => 'open',
]
);
if (!$report->wasRecentlyCreated) {
// If already exists, update reason/details in case user adds more context
$report->update([
'reason' => $validated['reason'],
'details' => $validated['details'] ?? $report->details,
'summary_id' => optional($book->summary)->id,
]);
}
return back()->with('success', 'Thanks! Your report has been submitted. We will review it soon.');
}
}