Ternary Blade operator without the other
I have an object that has a method hasATest
that returns a boolean and depending on the value I want the button to be enabled or disabled, so I thought about 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 with the other. If I delete :
, an error occurs:
"unexpected =" ...
Plus it doesn't feel like the opposite for the disabled.
+3
source to share
3 answers
Just use an empty line 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 use @if
ternary for it instead.
<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>
+1
source to share