<x-button color="red" />
@props(['color' => 'green'])
<button {{ $attributes->merge(['class' => 'bg-'.$color.'-500 rounded shadow-sm']) }}>
{{ $slot }}
</button>
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Does anyone have any ideas on how I can make a class via Laravel attribute forwarding take precedence over whatever default style is on the component?
<!-- Component -->
<x-button class="bg-red-500" />
<!-- /resources/views/components/button.blade.php -->
<button {{ $attributes->merge(['class' => 'bg-green-500 rounded shadow-sm']) }}>
{{ $slot }}
</button>
Basically what I want is if bg-red-500 is provided, then make it overwrite the default bg-green-500 but keep the other classes, otherwise just use bg-green-500.
Please or to participate in this conversation.