Reputation: 1359
I am trying to shorthand if statement inside HTML tag in Laravel blade file in this way:
<x-checkbox name="enable" id="enable" {{ ($settings->enable) ? 'checked' : '' }}>
{{ __('Enable') }}
</x-checkbox>
But its getting this error syntax error, unexpected 'endif' (T_ENDIF)
. I looked into similar questions and tried the solutions, but still getting same error. Any suggestion? Thanks in advance.
Edit: Checkbox component
<label class="inline-flex items-center mt-3">
<input
{{ $attributes->merge(['class' => 'form-checkbox h-5 w-5 rounded text-indigo-600']) }}
name="{{ $name }}"
id="{{ $name }}"
type="checkbox"
>
<span class="ml-2 text-gray-900 text-md font-medium">{{ $slot }}</span>
</label>
Upvotes: 2
Views: 1572
Reputation: 15319
Erorr thrown for this line
<x-checkbox name="enable" id="enable" {{ ($settings->enable) ? 'checked' : '' }}>
So change
<x-checkbox name="enable" id="enable" checked="{{$settings->enable}}">
{{ __('Enable') }}
</x-checkbox>
then in component
@props([
'checked'=>false,
])
<label class="inline-flex items-center mt-3">
<input
{{ $attributes->merge(['class' => 'form-checkbox h-5 w-5 rounded text-indigo-600']) }}
name="{{ $name }}"
id="{{ $name }}"
type="checkbox" {{$checked?'checked':''}}
>
<span class="ml-2 text-gray-900 text-md font-medium">{{ $slot }}</span>
</label>
Upvotes: 2