Description
Automatically resolves Tailwind CSS class conflicts in Laravel
Create your Blade components as you normally would, but instead of specifying the class attribute directly, use the mergeClasses method:
// circle.blade.php<div {{ $attributes->twMerge('w-10 h-10 rounded-full bg-red-500') }}></div>
Now you can use your Blade components and pass additional classes to merge:
// your-view.blade.php<x-circle class="bg-blue-500" />
This will render the following HTML:
<div class="w-10 h-10 rounded-full bg-blue-500"></div>
Note: Usage of
$attributes->merge(['class' => '...'])is currently not supported due to limitations in Laravel.
Recent Courses on Laravel Daily
Next.js Basics for Laravel Developers
11 lessons
58 min
Roles and Permissions in Laravel 13
14 lessons
57 min
Queues in Laravel 13
18 lessons
1 h 12 min read