我想将div嵌套在这样的循环中
Content
Content
Content
我正在考虑递归,但是我不确定如何在刀片中实现它.
解决方法:
您可以使用include调用Blade中的嵌套内容:
example.blade.php:
{{ $content->data }}
@if ($content->hasNestedData())
@include('viewfolder.example', $content->nestedContent)
@endif
要检查嵌套内容,可以在模型中实现如下功能:
public function hasNestedData()
{
return $this->nestedContent !== null;
}
并将嵌套内容设置为属性,例如:
public function nestedContent()
{
return $this->belongsTo(Content::class, 'nested_content_id');
}
由于您没有发布已经拥有的代码,因此将其用作主要思想.
标签:laravel,php
来源: https://codeday.me/bug/20191025/1928263.html