小编ssa*_*gki的帖子

在Laravel中使用Blade的嵌套注释

我正试图用Laravel中的Blade生成嵌套注释.似乎我必须制作一个刀片模板,其中包含为每个注释预先配置的无限嵌套注释以及它的子注释.但我希望评论能够自动生成.

这是我的评论模型:

class Comment extends Model {

    protected $table = 'comments';

    public function user()
    {
        return $this->hasOne('App\Models\User', 'id', 'user_id');
    }

    public function post()
    {
        return $this->hasOne('App\Models\Post', 'id', 'post_id');
    }

    public function children()
    {
        return $this->hasMany('App\Models\Comment', 'parent_id', 'id');
    }

}
Run Code Online (Sandbox Code Playgroud)

在我看来,我正在做

@foreach($comments as $comment)
<!-- Comment markup -->
    @if($comment->children->count() > 0)
        @foreach($comment->children as $child)
        <!-- Child comment markup -->
        @if($child->children->count() > 0) // I have to do this unlimited times
            @foreach ....

            @endforeach
        @endif
    @endif
@endforeach
Run Code Online (Sandbox Code Playgroud)

我正在寻找一种自动化方法,可能还有功能或其他东西.

php laravel blade

2
推荐指数
1
解决办法
2219
查看次数

标签 统计

blade ×1

laravel ×1

php ×1