Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

120
Vistas
Blade ternary operator without else

I've got a object which has the method hasATest that returns a boolean and depending on the value I want a button to be enabled or disabled so I thought of doing something like this:

<button class="btn btn-xs btn-detail btn-activate" name="question_id" value="{{$question->id}}" id="activate{{$question->id}}"
    "{{ $question->hasATest() ? disabled : }}"> Activate 
</button>

But I don't know what to do about the else. If I remove the :, an error occurs:

"unexpected ="  ... 

Plus it's not like there's the opposite for disabled.

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

The ternary operator needs an else as you already discovered, you could try some statements like null or in this case "" to return empty values on the else.

{{ ($question->hasATest()) ? "disabled" : "" }}

about 4 years ago · Santiago Trujillo Denunciar

0

Just use an empty string for the else part.

<button class="btn btn-xs btn-detail btn-activate" name="question_id" value="{{$question->id}}" id="activate{{$question->id}}"
    {{ $question->hasATest() ? 'disabled' : '' }}> Activate 
</button>

I think you could also use an @if for it instead of a ternary.

<button class="btn btn-xs btn-detail btn-activate" name="question_id" value="{{$question->id}}" id="activate{{$question->id}}"
    @if($question->hasATest()) disabled @endif> Activate
</button>
about 4 years ago · Santiago Trujillo Denunciar

0

You have problem in this line:

"{{ $question->hasATest() ? disabled : }}"

Here is the solution:

{{ ($question->hasATest()) ? disabled : 'enable' }}
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda