forelse laravel
snippet in php

laravel if syntax

user5165

@if (foo)
  // do something
@elseif (bar)
  // do something else
@else
  // do some other thing;
@endif

forelse laravel

user2816

@forelse ($users as $user)
    <li>{{ $user->name }}</li>
@empty
    <p>No users</p>
@endforelse

for else laravel

user4098

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

@forelse ($users as $user)
    <li>{{ $user->name }}</li>
@empty
    <p>No users</p>
@endforelse

forelse blade

user9780

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>

@foreac laravel

user163

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

@forelse ($users as $user)
    <li>{{ $user->name }}</li>
@empty
    <p>No users</p>
@endforelse