Php 如何限制laravel中回复评论的深度
我可以通过递归创建无限的回复评论。这件事可能很糟糕,因为我的网络看起来很丑 我希望用户只可以回复评论最大3个深度的回复评论,因此如果深度超过最大深度,评论不会再次创建嵌套 这里是我的代码,我可以尝试到目前为止,在blog.detail.php显示评论Php 如何限制laravel中回复评论的深度,php,laravel,comments,Php,Laravel,Comments,我可以通过递归创建无限的回复评论。这件事可能很糟糕,因为我的网络看起来很丑 我希望用户只可以回复评论最大3个深度的回复评论,因此如果深度超过最大深度,评论不会再次创建嵌套 这里是我的代码,我可以尝试到目前为止,在blog.detail.php显示评论 @include('nested.replies', ['comments' => $post->comments, 'post_id' => $parameter, 'depth' => 0]) 在repress.php
@include('nested.replies', ['comments' => $post->comments, 'post_id' => $parameter, 'depth' => 0])
在repress.php中
@foreach($comments->sortByDesc('created_at') as $comment)
<?php
$parameter = Hashids::connection()->encode($post->id);
$parameter2 = Hashids::connection()->encode($comment->id);
?>
<ol class="comments-list display-comment">
<li>
<div class="comment-box clearfix" >
<div class="avatar"><img alt="" src="{{ asset('frontboard/images/avatar.png') }}" /></div>
<div class="comment-content" id="reply?{{ $parameter2 }}">
<div class="comment-meta">
<span class="comment-by">{{ $comment->user->name }}</span>
<span class="comment-date">{{ $comment->date }}</span>
</div>
<span class="reply-link" stle="padding-top:-220px;">
<p>{{ $comment->body }}</p>
@if(Auth::guard('member')->check() && Auth::guard('member')->user()->active == 1)
@if(Auth::guard('member')->user()->isBan == 1)
<span class="reply-link">
Blocked
@else
{!! Form::open(['method' => 'DELETE','route' => ['comment.destroy', $comment->id]]) !!}
{!! Form::submit('delete', ['onclick' => 'return confirm("Are you sure?");','class' => 'btn btn-danger btn-xs pull-right'])!!}
{!! Form::close() !!}
<a href="#" class="replyform">Reply</a>
{!! Form::open([
'route' => ['reply.add', $post->slug],
'class' => 'showActionComment',
'data-parsley-validate'])
!!}
@csrf
<div class="form-group {{ $errors->has('comment_body') ? 'has-error': '' }}">
{!! Form::textarea('comment_body', null, [
'name' => 'comment_body',
'class' => 'form-control',
'placeholder' => 'Write Something.. ',
'required', 'minlength="4"'])
!!}
@if($errors->has('comment_body'))
<span class="help-block">{{$errors->first('comment_body')}}</span>
@endif
{!! Form::hidden('post_id', $parameter) !!}
{!! Form::hidden('comment_id', $parameter2) !!}
</div>
<div class="form-group">
<input type="submit" id="postBtn" value="Add Comment" />
<input type="button" class="btn1 btn-warning" value="Hide" />
</div>
{!! Form::close() !!}
@endif
@endif
</span>
</div>
</div>
@if($depth < 3)
<ul>
<li>
@include('nested.replies', ['comments' => $comment->replies, 'depth' => $depth + 1])
</li>
</ul>
@endif
</li>
</ol>
@endforeach
@foreach($comments->sortByDesc('created_at')作为$comment)
{{$comment->user->name}
{{$comment->date}
{{$comment->body}
@if(Auth::guard('member')->check()&&Auth::guard('member')->user()->active==1)
@if(Auth::guard('member')->user()->isBan==1)
此 路 不通
@否则
{!!Form::open(['method'=>'DELETE','route'=>['comment.destroy',$comment->id]])
{!!Form::submit('delete',['onclick'=>'返回确认(“你确定吗?”);','class'=>'btn btn危险btn xs向右拉')
{!!Form::close()!!}
{!!Form::open([
'route'=>['reply.add',$post->slug],
'class'=>'showActionComment',
'数据欧芹验证'])
!!}
@csrf
{!!Form::textarea('comment_body',null[
'name'=>'comment_body',
“类”=>“窗体控件”,
“占位符”=>“写点东西…”,
“必需”,“minlength=“4”]”)
!!}
@如果($errors->has('comment_body'))
{{$errors->first('comment_body')}
@恩迪夫
{!!Form::hidden('post_id',$parameter)!!}
{!!Form::hidden('comment_id',$parameter2)!!}
{!!Form::close()!!}
@恩迪夫
@恩迪夫
@如果($depth<3)
-
@包括('nested.replays',['comments'=>$comment->replays,'depth'=>$depth+1])
@恩迪夫
@endforeach
我们可以在这里看到回复
@if($depth < 3)
<ul>
<li>
@include('nested.replies', ['comments' => $comment->replies, 'depth' => $depth + 1])
</li>
</ul>
@endif
@if($depth<3)
-
@包括('nested.replays',['comments'=>$comment->replays,'depth'=>$depth+1])
@恩迪夫
我认为这段代码工作不正常,因为它仍然执行嵌套注释