With an example it is understood, it simply goes through all the values of the array/collection that you pass to it and if it is empty the else is skipped.
@forelse($array as $objeto_individual)
<h1> {{ $objeto_individual }}</h1>
@empty
<h1> Sin valores </h1>
@forelse
It's the same as a foreach, but in case the input parameter is empty, it will show whatever is between
@empty
and@endforelse
.The goal of
@forelse
is to reduce the code needed to do:to this:
In case you want to see how the Blade compilation is done: https://github.com/laravel/framework/blob/5.4/src/Illuminate/View/Compilers/Concerns/CompilesLoops.php#L14
With an example it is understood, it simply goes through all the values of the array/collection that you pass to it and if it is empty the else is skipped.
To complement @Shaz's answer:
It
forelse
not only checks if the variable is empty, but also if it is set, that is, it validates"empty"
e"isset"
.