user16333885
user16333885

Reputation:

Laravel: Weird Unexpected 'endif'

I'm trying to load some data from the DB into my View and I have coded this:

@forelse($wallets as $wallet)
    <td>{{ $wallet->title }}</td>
    <td>{{ $wallet->name }}</td>
    <td>
    @if(($wallet->is_active)==1)
        Active
    @else
        Deactive
    @endif
    </td>
    <td>
    @if(($wallet->is_cachable)==1)
        Cachable
    @else
        Un Cachable
    @endif
    </td>
@endforelse

But I get this:

syntax error, unexpected 'endif' (T_ENDIF)

However, as you can see I have closed the ifs properly by saying: @endif

So what is going wrong here?

Upvotes: 1

Views: 59

Answers (1)

Sumit Wadhwa
Sumit Wadhwa

Reputation: 3217

Your syntax for @forelse is wrong.

You need to place an @empty somewhere in-between which will be rendered when $wallets is empty:

@forelse($wallets as $wallet)

  <td>{{ $wallet->title }}</td>
  <td>{{ $wallet->name }}</td>
  <td>
    @if(($wallet->is_active)==1)
      Active
    @else
      Deactive
    @endif
  </td>
  <td>
    @if(($wallet->is_cachable)==1)
      Cachable
    @else
      Un Cachable
    @endif
 </td>

@empty    

  <p>No wallet data available</p>

@endforelse

Looping in blade.

Upvotes: 3

Related Questions