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
[NEW] Practical Laravel Security: Packages, Secrets, Supply-Chain Attacks
7 lessons
43 min read
Laravel 13 Starter Kit Teams and Customizations
10 lessons
33 min
How to Build Laravel 13 API From Scratch
30 lessons
1 h 23 min