I have add comments to the article, here are all the fields
Schema::create('article_comments', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('article_id');
$table->foreign('article_id')
->references('id')->on('articles')->onDelete('cascade');
$table->string('name');
$table->string('email');
$table->text('text');
$table->string('date');
$table->unsignedBigInteger('comment_id')->nullable();
$table->foreign('comment_id')
->references('id')->on('article_comments')->onDelete('set null');
$table->timestamps();
});
I have 2 blocks of comments, one regular and the second answer to it. The only difference between them is the different classes
This is how I bring them out
Normal comment
<div class="comment-list">
@foreach($article_comments as $article_comment)
<div class="comment-list__item">
<div class="item-card">
<div class="item-card__header">
<div class="item-card__title">
<div class="label">
{!! $article_comment->name !!}
</div>
<div class="data">
{!! date('d F Y', strtotime($article_comment->date)) !!}
</div>
</div>
</div>
<div class="item-card__content">
{!! $article_comment->text !!}
</div>
</div>
</div>
@endforeach
</div>
The reply to him
<div class="comment-sub-list">
<div class="comment-sub-list__item">
<div class="item-card">
<div class="item-card__header">
<div class="item-card__title">
<div class="label">
{!! $article_comment->name !!}
</div>
<div class="data">
{!! date('d F Y', strtotime($article_comment->date)) !!}
</div>
</div>
</div>
<div class="item-card__content">
{!! $article_comment->text !!}
</div>
</div>
</div>
</div>
If the comment_id field is filled in, then this will be the answer to the comment with this ID, but I can't implement it
I'm trying to type-check for the presence of the comment_id field and display this comment
$articleCommentsReply = $article_comments->where('comment_id', $article_comment->comment_id)
->whereNotNull('comment_id')
->first();
But in the end, this comment is displayed twice, and one of them is the answer to it