@darion
In Laravel, you can get the user object associated with a comment by using relationships and eager loading. Here's an example of how you can do this:
1 2 3 4 5 6 7 |
class Comment extends Model
{
public function user()
{
return $this->belongsTo(User::class);
}
}
|
1
|
$comments = Comment::with('user')->get();
|
1 2 3 4 |
@foreach ($comments as $comment)
<p>{{ $comment->content }}</p>
<p>Comment by: {{ $comment->user->name }}</p>
@endforeach
|
This way, you can easily get the user object associated with each comment in Laravel.