php for循环div,php-Laravel在循环中嵌套div

我想将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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值