Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

marcow's avatar
Level 13

disable blade button

I need to disable an x-button blade component based on a condition. On a normal button I do it like this:

<button type="submit" class="mb-2 mr-2 text-black" {{ ($disabled) ? ' disabled' : '' }}>CAPTION</button>

When I change this to use the x-button component:

<x-button type="submit" class="..." {{ ($disabled) ? ' disabled' : '' }}>CAPTION</x-button>

it doesn't work but throws: syntax error, unexpected token "endif"

The components/button.blade.php is very simple

<button {{ $attributes->merge(['type' => 'submit', 'class' => '...']) }}>{{ $slot }}</button>

Obviously the blade component does not use the disabled global attribute, even if i call it like

<x-button type="submit" class="..." disabled>CAPTION</x-button>

this will not work as expected but renders to

<button type="submit" class="..." disabled="disabled">Equip</button>

Can someone give me a hint how to change the component so that I can apply the "disabled" global attribute to the button element? Thx Marco

0 likes
4 replies
webrobert's avatar
Level 51

@marcow

Make disabled a prop of the component. And move your logic inside the component.

1 like
marcow's avatar
Level 13

@webrobert thanks for your reply. I allready tried that by changing:

<x-button type="submit" class="..." :disabled="true">CAPTION</x-button>
// component:
<button {{ $attributes->merge(['type' => 'submit', 'class' => '...']) }} {{ $disabled ?? false ? ' disabled' :'' }} >
    {{ $slot }}
</button>

but this also does not render correctly. Only in the button payload I can display the prop

marcow's avatar
Level 13

@webrobert sorry I forgot the @props. After adding it like this it works fine.

<x-button type="submit" class="..." :disabled="true">CAPTION</x-button>
// component:
@props(['disabled'=>false])
<button {{ $attributes->merge(['type' => 'submit', 'class' => '...']) }} {{ $disabled ?? false ? ' disabled' :'' }} >
    {{ $slot }}
</button>

Thx

2 likes

Please or to participate in this conversation.