first commit

This commit is contained in:
2026-06-10 10:46:22 +05:45
commit 473bdd627b
136 changed files with 19074 additions and 0 deletions
@@ -0,0 +1,49 @@
<?php
namespace App\Http\Controllers;
use App\Models\Comment;
use App\Models\Registration;
use Illuminate\Http\Request;
class CommentController extends Controller
{
public function index(Request $request)
{
$request->validate(['registration_id' => 'required|exists:registrations,id']);
$comments = Comment::where('registration_id', $request->registration_id)
->orderBy('created_at', 'asc')
->get()
->map(fn($c) => [
'comment' => $c->comment,
'author' => auth()->user()->name,
'created_at_human' => $c->created_at->diffForHumans(),
]);
return response()->json(['comments' => $comments]);
}
public function store(Request $request)
{
$request->validate([
'registration_id' => 'required|exists:registrations,id',
'comment' => 'required|string|max:1000',
]);
Registration::findOrFail($request->registration_id);
$comment = Comment::create([
'registration_id' => $request->registration_id,
'comment' => $request->comment,
]);
return response()->json([
'comment' => [
'comment' => $comment->comment,
'author' => auth()->user()->name,
'created_at_human' => $comment->created_at->diffForHumans(),
]
]);
}
}