例子:
如果用户id是1就跳过循环,这里我们forelse当没有数据的时候默认输出一些提示信息:
- @forelse($data as $item)
- @if($item->id == 1)
- <?php continue;?>
- @endif
- <p>{{$item->name}}</p>
- @empty
- <div>还没有用户请添加</div>
- @endforelse
来自 https://www.inbeijing.org/archives/1308
How to use break, continue, return statements is a blade template
You don't :)
Well, you can do normal PHP inside it but depends on why you'd want to do that... maybe a foreach break?
Usually you wouldn't need to, but if you must, use <?php return; ?>
@bashy Yes. Isn't blade support for break statements? Or can we extend blade?
I don't think there's any native support for break, no.
You need to put it inside the php tag: and so on...
@intrip we've said about that already.
@foreach ($value_array as $value) @if ($value == 'end') @break; @endif {{ $value }}
@endforeach
That's because break doesnt exist. It's easy to extend.
why do we use blade again?
@t0ne Can use what you want.
Its simple to Use break inside the blade template. You can just put the php script inside the blade like , It will work and I used this method and got succeed.
@break doesn't seem to work in 5.1, just FYI