laravel blade forelse code example
Example 1: forelse laravel
@forelse ($users as $user)
<li>{{ $user->name }}</li>
@empty
<p>No users</p>
@endforelse
Example 2: forach in larvel blade
@forelse ($array as $element)
@empty
@endforelse
Example 3: forelse blade
public function index()
{
$products = Product::get();
return view('home',compact('products'));
}
<div class="card-header">
<h5>Laravel Check Array Empty in Blade </h5>
</div>
<div class="card-body">
@forelse ($products as $product)
<p class="bg-danger text-white p-1">product</p>
@empty
<p class="bg-danger text-white p-1">No product</p>
@endforelse
</div>