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.
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" : "" }}
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With