displaying comments
This commit is contained in:
parent
e411e6297a
commit
75ebb57dd3
@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use App\Models\User;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Comment extends Model
|
||||
{
|
||||
@ -14,4 +16,9 @@ class Comment extends Model
|
||||
"post_id",
|
||||
"comment"
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
|
@ -24,4 +24,9 @@ class Post extends Model
|
||||
"username"
|
||||
]);
|
||||
}
|
||||
|
||||
public function comments()
|
||||
{
|
||||
return $this->hasMany(Comment::class);
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +53,23 @@
|
||||
class="bg-sky-600 hover:bg-sky-700 transition-colors cursor-pointer uppercase font-bold w-full p-3 text-white rounded-lg">
|
||||
</form>
|
||||
@endauth
|
||||
|
||||
<div class="bg-white shadow mb-5 max-h-96 overflow-y-scroll mt-10">
|
||||
@if ($post->comments->count() > 0)
|
||||
@foreach ($post->comments as $comment)
|
||||
<div class="p-5 border-gray-300 border-b">
|
||||
<a href="{{ route('posts.index', $comment->user) }}" class="font-bold">
|
||||
{{ $comment->user->username }}
|
||||
</a>
|
||||
|
||||
<p>{{ $comment->comment }}</p>
|
||||
<p class="text-sm text-gray-500">{{ $comment->created_at->diffForHumans() }}</p>
|
||||
</div>
|
||||
@endforeach
|
||||
@else
|
||||
<p class="p-10 text-center">No comments yet...</p>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user