Home > Backend Development > PHP Tutorial > laravel 数据嵌套循环

laravel 数据嵌套循环

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:34:03
Original
1070 people have browsed it

目前 有这么的需求 类似 二级导航一样的

现在有一组 大类别的表 和一组小类别的表 ; 循环大类别 的时候分别循环出 当前大类别下的 小类别

Eloquent ORM 怎么做呢 两个表怎么关联呢

另外

<code>@foreach ($users as $user)
    <p>This is user {{ $user->id }}</p>
@endforeach
</code>
Copy after login
Copy after login

这样的循环 怎么做多个嵌套循环呢

我是这么做的

大类数据是 $type
小类数据是 $types

<code> @foreach($type as $t)
            <ul>{{$t->btype_name}}</ul>
            @foreach($types as $ts)
                @if (count($t->id) ===count($ts->id))
                <li>{{$ts->stype_name}}</li>               
                @endif
            @endforeach
@endforeach
</code>
Copy after login
Copy after login

好像都循环出来了 并没有只循环当前大类下的 小类

回复内容:

目前 有这么的需求 类似 二级导航一样的

现在有一组 大类别的表 和一组小类别的表 ; 循环大类别 的时候分别循环出 当前大类别下的 小类别

Eloquent ORM 怎么做呢 两个表怎么关联呢

另外

<code>@foreach ($users as $user)
    <p>This is user {{ $user->id }}</p>
@endforeach
</code>
Copy after login
Copy after login

这样的循环 怎么做多个嵌套循环呢

我是这么做的

大类数据是 $type
小类数据是 $types

<code> @foreach($type as $t)
            <ul>{{$t->btype_name}}</ul>
            @foreach($types as $ts)
                @if (count($t->id) ===count($ts->id))
                <li>{{$ts->stype_name}}</li>               
                @endif
            @endforeach
@endforeach
</code>
Copy after login
Copy after login

好像都循环出来了 并没有只循环当前大类下的 小类

我觉得你的代码有问题呀。最近我也在看lava5
感觉非常好的工具。原来一直用think PHP。对比了一下。think PHP确实不行。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Composer cannot install laravel
From 1970-01-01 08:00:00
0
0
0
Laravel Space/laravel-backup cannot be installed
From 1970-01-01 08:00:00
0
0
0
Laravel 5.1 Login laravel comes with it No more
From 1970-01-01 08:00:00
0
0
0
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template