1@if (foo)
2 // do something
3@elseif (bar)
4 // do something else
5@else
6 // do some other thing;
7@endif
1@forelse ($users as $user)
2 <li>{{ $user->name }}</li>
3@empty
4 <p>No users</p>
5@endforelse
1@foreach ($users as $user)
2 <p>This is user {{ $user->id }}</p>
3@endforeach
4
5@forelse ($users as $user)
6 <li>{{ $user->name }}</li>
7@empty
8 <p>No users</p>
9@endforelse
1public function index()
2
3{
4
5 $products = Product::get();
6
7 return view('home',compact('products'));
8
9}
10
11<div class="card-header">
12
13 <h5>Laravel Check Array Empty in Blade </h5>
14
15</div>
16
17<div class="card-body">
18
19 @forelse ($products as $product)
20
21 <p class="bg-danger text-white p-1">product</p>
22
23 @empty
24
25 <p class="bg-danger text-white p-1">No product</p>
26
27 @endforelse
28
29</div>
1@foreach ($users as $user)
2 <p>This is user {{ $user->id }}</p>
3@endforeach
4
5@forelse ($users as $user)
6 <li>{{ $user->name }}</li>
7@empty
8 <p>No users</p>
9@endforelse
10