is forelse remove in laravel 4.2.4?
Date : March 29 2020, 07:55 AM
will be helpful for those in need I don't think @forelse has been around since Laravel 3. I could be wrong. I know it was removed at some point though. You need to use a standard @if and @foreach now. @if (empty($result))
<tr><td>No name match</td></tr>
@else
@foreach ($result as $data)
<tr><td> $data->name </td></tr>
@endforeach
@endif
|
Difference between foreach and forelse in Laravel
Date : March 29 2020, 07:55 AM
This might help you I believe the answer to your question is that, essentially, ForElse is a ForEach loop, but with extra handling for empty input(s). From the Laravel 5 docs on Blade Templates, an example illustrating both loops with the same list of Users as Input: @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
/**
* Compile the for-each statements into valid PHP.
*
* @param string $expression
* @return string
*/
protected function compileForeach($expression)
{
preg_match('/\( *(.*) +as *(.*)\)$/is', $expression, $matches);
$iteratee = trim($matches[1]);
$iteration = trim($matches[2]);
$initLoop = "\$__currentLoopData = {$iteratee}; \$__env->addLoop(\$__currentLoopData);";
$iterateLoop = '$__env->incrementLoopIndices(); $loop = $__env->getLastLoop();';
return "<?php {$initLoop} foreach(\$__currentLoopData as {$iteration}): {$iterateLoop} ?>";
}
/**
* Compile the for-else statements into valid PHP.
*
* @param string $expression
* @return string
*/
protected function compileForelse($expression)
{
$empty = '$__empty_'.++$this->forElseCounter;
preg_match('/\( *(.*) +as *(.*)\)$/is', $expression, $matches);
$iteratee = trim($matches[1]);
$iteration = trim($matches[2]);
$initLoop = "\$__currentLoopData = {$iteratee}; \$__env->addLoop(\$__currentLoopData);";
$iterateLoop = '$__env->incrementLoopIndices(); $loop = $__env->getLastLoop();';
return "<?php {$empty} = true; {$initLoop} foreach(\$__currentLoopData as {$iteration}): {$iterateLoop} {$empty} = false; ?>";
}
|
laravel blade append to @section in @forelse
Date : March 29 2020, 07:55 AM
To fix this issue My main template blade has a @yield('section_name') in the tag to append css/ js. Now I have a forelse like this: , Use @append instead of @endsection @forelse($collection as $item)
some text
@section('section_name')
// link to stylesheet
@append
@empty
// something went wrong
@endforelse
|
Laravel @foreach and @forelse
Date : March 29 2020, 07:55 AM
To fix this issue I have a problem with my view of laravel. I have a field that executes a loop, and if it has data in the field it list, but if it does not it only shows me nothing. , KISS and just use @if / @else: <em>{{ $prices->price ?? ' - ' }}</em> <br>
@if($prices && $prices->infos_home)
@foreach($prices->infos_home as $info)
<em>{{ $info }}</em> <br>
@endforeach
@else
<em> - </em>
@endif
|
Access relation in forelse on the same model - laravel
Date : March 29 2020, 07:55 AM
This might help you To eager load a distant relationship you can use the dot notation like so: $category = Category::with('translation', 'childCategories.translations')
->active()
->where('id', $id)
->first();
|