laravel停止在循环中嵌套回复表单



如何阻止回复表单在回复后显示和重复它自己

@foreach($comments as $comment)
<div class="display-comment">
<strong>{{ $comment->user->name }}</strong>
<p>{{ $comment->comment }}</p>
<a href="" id="reply"></a>
<form method="post" action="{{ route('reply.add') }}">
@csrf
<div class="form-group">
<input type="text" name="comment" class="form-control" />
<input type="hidden" name="post_id" value="{{ $post_id }}" />
<input type="hidden" name="comment_id" value="{{ $comment->id }}" />
</div>
<div class="form-group">
<input type="submit" class="py-0 btn btn-sm btn-outline-danger" style="font-size: 0.8em;" value="Reply" />
</div>
</form>
@include('posts.comments.reply', ['comments' => $comment->replies])
</div>
@endforeach
@forelse($comments as $comment)
<div class="display-comment">
<strong>{{ $comment->user->name }}</strong>
<p>{{ $comment->comment }}</p>
@include('posts.comments.reply', ['comments' => $comment->replies])
</div>
@empty
<div> No comments found</div>
@endforelse
<form method="post" action="{{ route('reply.add') }}">
@csrf
<div class="form-group">
<input type="text" name="comment" class="form-control" />
<input type="hidden" name="post_id" value="{{ $post_id }}" />
<input type="hidden" name="comment_id" value="{{ $comment->id }}" />
</div>
<div class="form-group">
<input type="submit" class="py-0 btn btn-sm btn-outline-danger" style="font-size: 0.8em;" value="Reply" />
</div>
</form>

你应该能算出来。没那么棘手

@if (!empty($comment->replies))
@include('posts.comments.reply', ['comments' => $comment->replies])
@empty

最新更新