In a Laravel component, how to do I remove a default class?

690 Views Asked by At

In a Laravel component, you can specify default classes and merge them with extra classes that get passed in, something like this:

<a {{ $attributes->merge(['class' => 'text-white']) }}>{{ $slot }}</a>

But what if I want to remove that "text-white" class? How can I pass in a list of classes to exclude from the component?

1

There are 1 best solutions below

0
Wahyu Kristianto On

You need to use conditionally merge classes. You can accomplish this via the class method, which accepts an array of classes where the array key contains the class or classes you wish to add, while the value is a boolean expression.

<a {{ $attributes->class(['text-white' => $isTextWhite]) }}>{{ $slot }}</a>