Brent
Brent

Reputation: 2485

If Statment in a Loop Blade Laravel

I am trying to run condition a loop inside of larvel with blade with no luck. I can get the individual items out fine by {{$this->active}} but I want to check a value inside a loop.

Hope this makes sense.

   @foreach ($clients as $client)

       @if($client->active == 0){
           <a href="{{ URL::route('published', $client->id) }}/1">Published</a>
       @endif
       @if($client->active == 1){
          <a href="{{ URL::route('published', $client->id) }}/0">Unpublished</a>
       @endif

   @endforeach

Upvotes: 0

Views: 233

Answers (1)

Barryvdh
Barryvdh

Reputation: 6579

Try @foreach($clients as $client) (without the space), and @if($client->active == 0) without the { at the end.

@foreach($clients as $client)
    @if($client->active == 0)
        <a href="{{ URL::route('published', $client->id) }}/1">Published</a>
    @endif
    @if($client->active == 1)
        <a href="{{ URL::route('published', $client->id) }}/0">Unpublished</a>
    @endif
@endforeach

(Posted as comment, but is the answer)

Upvotes: 1

Related Questions