- How do I merge Tailwind CSS classes in Laravel using this package?
- Use `TailwindMerge::instance()->merge('class1', 'class2')` to merge classes, where later classes override earlier ones. For example, merging `text-red-500` and `text-blue-500` returns `text-blue-500`. Works seamlessly in Blade templates, Livewire components, or API responses.
- Does this package support Laravel’s Blade templating?
- Yes, it’s framework-agnostic but integrates perfectly with Laravel Blade. Use it directly in Blade files or pass merged classes to Livewire components. For deeper integration, pair it with the companion package `tailwind-merge-laravel`.
- What Laravel and PHP versions are supported?
- This package requires **PHP 8.1+** and works with Laravel 8.x–10.x. It’s compatible with Tailwind CSS v3.0–v3.4. If you’re using Laravel <8.0 or Tailwind v2.x/v4.x, you may need custom configuration or a fork.
- How do I customize conflict resolution for my Tailwind config?
- Use the factory method to create a custom instance: `TailwindMerge::factory()->withConfiguration(['classGroups' => [...]])`. This lets you define custom rules for non-standard Tailwind setups, like renamed classes or arbitrary values.
- Can I cache merged results for performance?
- Yes, the package supports PSR-16 caching (e.g., Laravel’s cache system). Enable it via `TailwindMerge::factory()->withCache($cache)` to store merged results, reducing runtime overhead for repeated merges in high-traffic applications.
- Will this break if I use non-Tailwind classes (e.g., custom CSS)?
- No, the package gracefully handles non-Tailwind classes by ignoring them during merging. Only Tailwind utilities are processed, so classes like `my-custom-class` remain untouched in the output.
- How does this compare to client-side merging (e.g., JavaScript tailwind-merge)?
- Server-side merging (PHP) is ideal for Laravel apps where classes are generated dynamically in Blade, Livewire, or APIs. Client-side merging (JS) is better for interactive UIs but adds bundle size. This package avoids client-side dependencies entirely.
- Does it support Tailwind’s dark mode, hover states, or arbitrary values?
- Yes, it handles dark mode classes (e.g., `dark:bg-gray-800`), hover/focus states (e.g., `hover:text-blue-600`), and arbitrary values (e.g., `[&>*:nth-child(2)]:text-red-500`). Test edge cases in your setup to ensure compatibility with custom configurations.
- Is there a Laravel-specific wrapper for easier integration?
- Yes, the companion package [`tailwind-merge-laravel`](https://github.com/gehrisandro/tailwind-merge-laravel) provides Laravel-specific helpers, like Blade directives and Livewire integration. Install it via `composer require gehrisandro/tailwind-merge-laravel`.
- How do I handle conflicts with custom Tailwind configurations (e.g., renamed classes)?
- If your `tailwind.config.js` uses custom class names or modified utilities, define them in `classGroups` via the factory. For example, `->withConfiguration(['classGroups' => ['custom' => ['.my-bg' => 'bg']]])` maps custom classes to Tailwind’s rules.