From 5c69f89de87cf1ec92ed763ef4d13579e33a4bc2 Mon Sep 17 00:00:00 2001 From: sampanna Date: Thu, 11 Jun 2026 13:14:01 +0545 Subject: [PATCH] comments user --- app/Http/Controllers/CommentController.php | 5 ++-- app/Models/Comment.php | 6 ++++ ...071428_add_createdby_to_comments_table.php | 28 +++++++++++++++++++ resources/views/auth/login.blade.php | 4 +-- resources/views/registrations.blade.php | 7 +++-- 5 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 database/migrations/2026_06_11_071428_add_createdby_to_comments_table.php diff --git a/app/Http/Controllers/CommentController.php b/app/Http/Controllers/CommentController.php index da69aae..9641169 100644 --- a/app/Http/Controllers/CommentController.php +++ b/app/Http/Controllers/CommentController.php @@ -17,7 +17,7 @@ class CommentController extends Controller ->get() ->map(fn($c) => [ 'comment' => $c->comment, - 'author' => auth()->user()->name, + 'author' => $c->author_name, 'created_at_human' => $c->created_at->diffForHumans(), ]) ->values(); // ← add this @@ -37,12 +37,13 @@ class CommentController extends Controller $comment = Comment::create([ 'registration_id' => $request->registration_id, 'comment' => $request->comment, + 'created_by' => auth()->id(), ]); return response()->json([ 'comment' => [ 'comment' => $comment->comment, - 'author' => auth()->user()->name, + 'author' => $comment->author_name, 'created_at_human' => $comment->created_at->diffForHumans(), ] ]); diff --git a/app/Models/Comment.php b/app/Models/Comment.php index 4e3caf7..a52c000 100644 --- a/app/Models/Comment.php +++ b/app/Models/Comment.php @@ -9,6 +9,7 @@ class Comment extends Model protected $fillable = [ 'registration_id', 'comment', + 'created_by', ]; /* @@ -36,4 +37,9 @@ class Comment extends Model ? substr($this->comment, 0, 50) . '...' : $this->comment; } + + public function getAuthorNameAttribute() + { + return User::findOrFail($this->created_by)?->name; + } } \ No newline at end of file diff --git a/database/migrations/2026_06_11_071428_add_createdby_to_comments_table.php b/database/migrations/2026_06_11_071428_add_createdby_to_comments_table.php new file mode 100644 index 0000000..46fc6bd --- /dev/null +++ b/database/migrations/2026_06_11_071428_add_createdby_to_comments_table.php @@ -0,0 +1,28 @@ +unsignedBigInteger('created_by')->default(1); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('comments', function (Blueprint $table) { + $table->dropColumn('created_by'); + }); + } +}; diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 78b684f..1fe0603 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -33,11 +33,11 @@
- @if (Route::has('password.request')) + {{-- @if (Route::has('password.request')) {{ __('Forgot your password?') }} - @endif + @endif --}} {{ __('Log in') }} diff --git a/resources/views/registrations.blade.php b/resources/views/registrations.blade.php index 36a97bd..f6f385a 100644 --- a/resources/views/registrations.blade.php +++ b/resources/views/registrations.blade.php @@ -60,6 +60,7 @@ $commentData = $reg->comments->sortByDesc('created_at')->map(fn($c) => [ 'comment' => $c->comment, + 'author' => $c->author_name, 'created_at' => $c->created_at->diffForHumans(), ])->values()->toArray(); @endphp @@ -291,6 +292,7 @@ function openDetailPanel(row) { const created = row.dataset.created; const sessions = JSON.parse(row.dataset.sessions || '[]'); const comments = JSON.parse(row.dataset.comments || '[]'); + console.log(comments); const countryTitle=row.dataset.countryTitle; const countryFlag=row.dataset.countryFlag; @@ -367,7 +369,7 @@ function renderPanelComments(comments) { el.innerHTML = comments.map(c => `
- Counselor + ${escHtml(c.author)} ${escHtml(c.created_at)}

${escHtml(c.comment)}

@@ -405,8 +407,9 @@ document.getElementById('panelCommentBtn').addEventListener('click', function () const list = Array.isArray(r.comments) ? r.comments : Object.values(r.comments || {}); renderPanelComments(list.map(c => ({ comment: c.comment, + author: c.author_name, created_at: c.created_at_human ?? c.created_at, - }))); + }))); } }); },