forelse laravel code example
Example 1: forelse laravel
@forelse ($users as $user)
{{ $user->name }}
@empty
No users
@endforelse
Example 2: laravel if syntax
@if (foo)
// do something
@elseif (bar)
// do something else
@else
// do some other thing;
@endif
Example 3: for else laravel
@foreach ($users as $user)
This is user {{ $user->id }}
@endforeach
@forelse ($users as $user)
{{ $user->name }}
@empty
No users
@endforelse
Example 4: 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
Example 5: @foreac laravel
@foreach ($users as $user)
This is user {{ $user->id }}
@endforeach
@forelse ($users as $user)
{{ $user->name }}
@empty
No users
@endforelse
Example 6: laravel foreach
public function times(){
$times = Times::all();
$bookings = Bookings::all();
return view('/test2')->with('times', $times)->with('bookings', $bookings);
}