Removing in laravel 4.2.4?

I tried using @forelse in laravel, but he gave me this error

 Undefined variable: data

is @forelse removed from laravel 4.2.4? because this is the version I'm using. This is my code.

in my opinion

@forelse ($result as $data)
  <tr><td> $data->name </td></tr>
@empty
  <tr><td>No name match</td></tr>
@endforelse

in my controller

$result = User::find(1)->get();
return View::make('view')->with('result', $result);
+4
source share
2 answers

I don’t think I @forelsewas around with Laravel 3. I could be wrong. I know that it was deleted at some point. Now you need to use the standard @ifand @foreach.

@if (empty($result))
  <tr><td>No name match</td></tr>
@else
  @foreach ($result as $data)
    <tr><td> $data->name </td></tr>
  @endforeach
@endif

UPDATE

As Antonio noted, it was returned and is available in v4.2.7 + , so you will need to update it if you want.

+4
source

. laracast Laravel 5 . , , if else count:

@if (count($result))
  has result
@ifelse
  has no result
@endif
+2

All Articles