Erasersharp
Erasersharp

Reputation: 368

If statement inside a foreach loop

@foreach ($image as $image)

        <div class="col-md-4">

        @if ($image->current_step == 'step'.$loop->iteration AND $image->isCompleted == '1')
            <div class="panel panel-success">

        @elseif ($image->current_step == 'step'.$loop->first OR $image->current_step == 'step'.$loop->index AND $image->isCompleted == '1')
            <div class="panel panel-default">

        @elseif ($image->current_step == 'step'.$loop->iteration AND $image->isCompleted == '0')
            <div class="panel panel-danger">


        @endif
@endforeach

I've created a loop to generate a number of panels, however I want the panels to be styled differently based off the correct if statements.

It seems to be getting stuck on the second if statement whenever it hits that part to ask if the previous steps condition has been met.

If anyone can point me in the general direction or another way I should be going.

Thanks

Upvotes: 0

Views: 620

Answers (1)

Gravy
Gravy

Reputation: 12445

Your second else if:

    $a = false;
    $b = true;
    $c = false;

    if ($a or $b and $c) {
        dd('a or b and c');
    }

    dd(false);

// Above snippet will output false. Is this intended?

You could write a truth table to help you out

A  B  C  |  A  |  B  &  C
-------------------------

0  0  0  |  0  0  0  0  0  
0  0  1  |  0  0  0  0  1  
0  1  0  |  0  0  1  0  0  
0  1  1  |  0  1  1  1  1  
1  0  0  |  1  1  0  0  0  
1  0  1  |  1  1  0  0  1  
1  1  0  |  1  1  1  0  0  
1  1  1  |  1  1  1  1  1  

Upvotes: 1

Related Questions