I’m new at Laravel and recently came across this problem. I’d like to override the background of my Laravel 11 component, but instead I’m just adding an extra class which is not rendered,ie the background does not change.
How can I solve this? For example:
<div {{$attributes->merge(['class' => 'bg-blue-100'])}}>
{{$slot}}
</div>
<x-card class="bg-black">
...
</x-card>
Instead of class="bg-black" I end up with class="bg-blue-100 bg-black". Is there anyway around it other than exluding bg-blue-100, because I’d like to have a default background.
Thanks
2
Answers
You can use component variables to solve this issue.
If
bgColor
isn’t specifically mentioned in thex-card
tag, the default value ofbg-blue-100
will be used.