comments user
This commit is contained in:
@@ -17,7 +17,7 @@ class CommentController extends Controller
|
|||||||
->get()
|
->get()
|
||||||
->map(fn($c) => [
|
->map(fn($c) => [
|
||||||
'comment' => $c->comment,
|
'comment' => $c->comment,
|
||||||
'author' => auth()->user()->name,
|
'author' => $c->author_name,
|
||||||
'created_at_human' => $c->created_at->diffForHumans(),
|
'created_at_human' => $c->created_at->diffForHumans(),
|
||||||
])
|
])
|
||||||
->values(); // ← add this
|
->values(); // ← add this
|
||||||
@@ -37,12 +37,13 @@ class CommentController extends Controller
|
|||||||
$comment = Comment::create([
|
$comment = Comment::create([
|
||||||
'registration_id' => $request->registration_id,
|
'registration_id' => $request->registration_id,
|
||||||
'comment' => $request->comment,
|
'comment' => $request->comment,
|
||||||
|
'created_by' => auth()->id(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'comment' => [
|
'comment' => [
|
||||||
'comment' => $comment->comment,
|
'comment' => $comment->comment,
|
||||||
'author' => auth()->user()->name,
|
'author' => $comment->author_name,
|
||||||
'created_at_human' => $comment->created_at->diffForHumans(),
|
'created_at_human' => $comment->created_at->diffForHumans(),
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ class Comment extends Model
|
|||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'registration_id',
|
'registration_id',
|
||||||
'comment',
|
'comment',
|
||||||
|
'created_by',
|
||||||
];
|
];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -36,4 +37,9 @@ class Comment extends Model
|
|||||||
? substr($this->comment, 0, 50) . '...'
|
? substr($this->comment, 0, 50) . '...'
|
||||||
: $this->comment;
|
: $this->comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAuthorNameAttribute()
|
||||||
|
{
|
||||||
|
return User::findOrFail($this->created_by)?->name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('comments', function (Blueprint $table) {
|
||||||
|
$table->unsignedBigInteger('created_by')->default(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('comments', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('created_by');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -33,11 +33,11 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center justify-end mt-4">
|
<div class="flex items-center justify-end mt-4">
|
||||||
@if (Route::has('password.request'))
|
{{-- @if (Route::has('password.request'))
|
||||||
<a class="underline text-sm text-gray-600 hover:text-gray-900 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" href="{{ route('password.request') }}">
|
<a class="underline text-sm text-gray-600 hover:text-gray-900 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" href="{{ route('password.request') }}">
|
||||||
{{ __('Forgot your password?') }}
|
{{ __('Forgot your password?') }}
|
||||||
</a>
|
</a>
|
||||||
@endif
|
@endif --}}
|
||||||
|
|
||||||
<x-primary-button class="ms-3">
|
<x-primary-button class="ms-3">
|
||||||
{{ __('Log in') }}
|
{{ __('Log in') }}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@
|
|||||||
|
|
||||||
$commentData = $reg->comments->sortByDesc('created_at')->map(fn($c) => [
|
$commentData = $reg->comments->sortByDesc('created_at')->map(fn($c) => [
|
||||||
'comment' => $c->comment,
|
'comment' => $c->comment,
|
||||||
|
'author' => $c->author_name,
|
||||||
'created_at' => $c->created_at->diffForHumans(),
|
'created_at' => $c->created_at->diffForHumans(),
|
||||||
])->values()->toArray();
|
])->values()->toArray();
|
||||||
@endphp
|
@endphp
|
||||||
@@ -291,6 +292,7 @@ function openDetailPanel(row) {
|
|||||||
const created = row.dataset.created;
|
const created = row.dataset.created;
|
||||||
const sessions = JSON.parse(row.dataset.sessions || '[]');
|
const sessions = JSON.parse(row.dataset.sessions || '[]');
|
||||||
const comments = JSON.parse(row.dataset.comments || '[]');
|
const comments = JSON.parse(row.dataset.comments || '[]');
|
||||||
|
console.log(comments);
|
||||||
|
|
||||||
const countryTitle=row.dataset.countryTitle;
|
const countryTitle=row.dataset.countryTitle;
|
||||||
const countryFlag=row.dataset.countryFlag;
|
const countryFlag=row.dataset.countryFlag;
|
||||||
@@ -367,7 +369,7 @@ function renderPanelComments(comments) {
|
|||||||
el.innerHTML = comments.map(c => `
|
el.innerHTML = comments.map(c => `
|
||||||
<div class="bg-slate-50 border border-slate-200 rounded-xl px-4 py-3">
|
<div class="bg-slate-50 border border-slate-200 rounded-xl px-4 py-3">
|
||||||
<div class="flex items-center justify-between mb-1.5">
|
<div class="flex items-center justify-between mb-1.5">
|
||||||
<span class="text-xs font-semibold text-indigo-600">Counselor</span>
|
<span class="text-xs font-semibold text-indigo-600">${escHtml(c.author)}</span>
|
||||||
<span class="text-xs text-slate-400">${escHtml(c.created_at)}</span>
|
<span class="text-xs text-slate-400">${escHtml(c.created_at)}</span>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-sm text-slate-700 leading-relaxed">${escHtml(c.comment)}</p>
|
<p class="text-sm text-slate-700 leading-relaxed">${escHtml(c.comment)}</p>
|
||||||
@@ -405,6 +407,7 @@ document.getElementById('panelCommentBtn').addEventListener('click', function ()
|
|||||||
const list = Array.isArray(r.comments) ? r.comments : Object.values(r.comments || {});
|
const list = Array.isArray(r.comments) ? r.comments : Object.values(r.comments || {});
|
||||||
renderPanelComments(list.map(c => ({
|
renderPanelComments(list.map(c => ({
|
||||||
comment: c.comment,
|
comment: c.comment,
|
||||||
|
author: c.author_name,
|
||||||
created_at: c.created_at_human ?? c.created_at,
|
created_at: c.created_at_human ?? c.created_at,
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user