- How do I install TailwindMerge for PHP in a Laravel app?
- Install it with Composer using composer require tales-from-a-dev/tailwind-merge-php. The package requires PHP 8.1 or newer and does not require a Laravel service provider. After installation, use the documented merger class or call it from Blade, Livewire, or a helper.
- Does TailwindMerge for PHP work with Laravel 10 and Laravel 11?
- It is framework-agnostic, so any Laravel version running on PHP 8.1 or newer can use it. There is no service provider or Laravel-specific coupling. Laravel 10 and 11 typically qualify as long as your application meets the PHP requirement.
- How is TailwindMerge different from Laravel's $attributes->merge()?
- Laravel's $attributes->merge() concatenates class values but does not resolve Tailwind utility conflicts. TailwindMerge removes earlier classes that are overridden by later ones, so the two tools compose rather than compete. Use $attributes->merge() for attribute bags and TailwindMerge for conflict-aware class lists.
- Which Tailwind CSS versions are supported by this package?
- It supports Tailwind v4.0 through v4.3. The package is a PHP port pinned to an upstream tailwind-merge version, so utilities added in later Tailwind minors may pass through unmerged until the pin moves. Check the changelog and fixture tests for exact parity.
- How do I merge Tailwind classes inside a Blade component?
- Build the complete class string in PHP and pass it through the merger before rendering. In Blade, call it from a component class, view composer, or helper instead of relying only on $attributes->merge(). This keeps conditional and override classes predictable.
- Can I cache Tailwind class merging for better performance?
- Yes, optional caching is documented for the package. Caching helps when the same class lists are merged repeatedly, such as in loops or high-traffic views. Measure first, because the precompiled default class map may be fast enough for simple one-off merges.
- What alternatives exist to TailwindMerge for PHP?
- The original gehrisandro/tailwind-merge-php is the upstream PHP port that this package forks. You can also avoid runtime merging by manually controlling class order, but that becomes error-prone with conditional Tailwind classes. This fork's main distinction is support for Tailwind v4.0 through v4.3 on PHP 8.1+.
- How do I configure custom Tailwind classes or prefixes?
- Configuration options are available for custom needs such as class groups and conflicting class groups. Because the default class map is precompiled, confirm how custom configuration layers on top and test representative classes. Pin the package version when relying on custom behavior.
- Is TailwindMerge for PHP safe to use in production?
- It is pre-1.0 and maintained by a single maintainer as a fork, so pin exact versions and review upgrade notes. The package is small and framework-agnostic, which limits integration risk. Production use should include tests for your critical class merges and a plan for Tailwind version updates.
- How should I test Tailwind class merging in my Laravel application?
- Test representative Tailwind class combinations that matter to your UI, especially conditional and override cases. The package's own fixture suite is the authoritative parity record, so mirror key cases in your app tests. Rerun tests after package upgrades because pre-1.0 minor releases can change behavior.