laravel continue code example

Example 1: laravel for loop

@for ($i = 0; $i < 10; $i++)
    The current value is {{ $i }}
@endfor

@foreach ($users as $user)
    

This is user {{ $user->id }}

@endforeach @forelse ($users as $user)
  • {{ $user->name }}
  • @empty

    No users

    @endforelse @while (true)

    I'm looping forever.

    @endwhile

    Example 2: laravel foreach first

    @foreach ($users as $user)
        @if ($loop->first)
            This is the first iteration.
        @endif
    
        @if ($loop->last)
            This is the last iteration.
        @endif
    
        

    This is user {{ $user->id }}

    @endforeach

    Example 3: forelse blade

    public function index()
    
    {
    
        $products = Product::get();
    
        return view('home',compact('products'));
    
    }
    
    
    Laravel Check Array Empty in Blade
    @forelse ($products as $product)

    product

    @empty

    No product

    @endforelse

    Tags:

    Misc Example