if and elseif in Laravel

1

I am taking data from a BD and depending on the number that I return, it has to show one class or another. I'm doing something like that but it does not work.

@if ($vivienda->etiqueta == 1)
  <p class="pLab">¡ {{ $vivienda->etiqueta }} !</p>
@elseif ($vivienda->etiqueta == 2)
  <p class="pLab2">¡ {{ $vivienda->etiqueta }} !</p>
@endif

If I put in place of elseif I put a else if it works, but of course I have to do up to 7 different states.

    
asked by Miguel 10.12.2018 в 21:13
source

1 answer

1

It is not easier to do this:

@switch(true)
    @case($vivienda->etiqueta == 1)
         <p class="pLab">¡ {{ $vivienda->etiqueta }} !</p>
        @break

    @case($vivienda->etiqueta == 2)
        <p class="pLab2">¡ {{ $vivienda->etiqueta }} !</p>
        @break
@endswitch

or maybe this way:

 <p class="pLab{{$vivienda->etiqueta}}">¡ {{ $vivienda->etiqueta }} !</p>
    
answered by 10.12.2018 / 21:27
source