comments user
This commit is contained in:
@@ -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(),
|
||||
]
|
||||
]);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user