'Conditional checked on laravel blade template

I'n trying to set checked a checkbox on laravel template depending on a php variable this way

<input name="gender" type="radio" value="Man" class="input-radio-gender" id="genderOther"  <% echo $consumerInfo['attributes']['gender']=='Man'?'checked':''%>>

But its not workig, what I hace to change?



Solution 1:[1]

use laravel @if directive here like this

<input name="gender" type="radio" value="Man" class="input-radio-gender" id="genderOther" 
 @if($consumerInfo['attributes']['gender'] =='Man')
  checked
 @endif
>

Solution 2:[2]

Shouldn't you use interpolation symbols {{}}? Below should work.

<input name="gender" type="radio" value="Man" class="input-radio-gender" id="genderOther"  {{ $consumerInfo['attributes']['gender']== 'Man'? 'checked="checked"' : '' }} />

Solution 3:[3]

This feature has been added since Laravel 9 Documentation

<input type="checkbox"
        name="active"
        value="active"
        @checked(old('active', $user->active)) />

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jignesh Joisar
Solution 2 nice_dev
Solution 3 Akbarali