Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Tailwind Merge Php Laravel Package

gehrisandro/tailwind-merge-php

TailwindMerge for PHP merges multiple Tailwind CSS classes and resolves conflicts automatically, keeping only the class defined later. A PHP port of tailwind-merge supporting Tailwind v3.0 through v3.4, requiring PHP 8.1+, with caching and configurable options.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Build vs. buy for design-system plumbing. Class-conflict resolution (e.g. a component default of px-6 being overridden by a passed-in pl-4) is a small, boring, high-frequency problem. Porting tailwind-merge yourself is a multi-week correctness rabbit hole involving arbitrary values, variants stacking, the !important modifier, and breakpoint ordering. This package converts that into a one-line Composer dependency, so the decision becomes "do we staff a utility library?" — and the answer is almost certainly no.
  • Component API design — "overridable by default." Adoption lets you commit to a product promise that base components accept and honor consumer overrides without !important hacks or class prop collision bugs. That is a roadmap-level decision about developer ergonomics for your design system, not just an implementation detail, and it directly reduces the ticket volume of "my style override didn't apply."
  • Theming and white-labeling strategy. Because merging is config-aware (prefix, custom classGroups), this package is the mechanism that makes per-tenant or per-brand Tailwind prefixes viable in a multi-tenant product. If multi-brand is on the roadmap, this is a cheap enabler; if it isn't, that capability is not worth paying the config-sync tax for.
  • Server-rendered styling surface area. Anything you render in PHP — Blade components, Livewire, mail templates, PDF/invoice generation, API-driven class strings — is where client-side tailwind-merge cannot help you. This package is what unlocks consistent styling for those surfaces, which matters if email/PDF output is a customer-visible product surface.
  • Performance budget for render-heavy pages. The optional PSR-16 cache is a lever you can turn on if class merging shows up in profiling of high-traffic pages, without changing the integration. That gives you a cheap escape hatch instead of a re-architecture.
  • Tailwind version strategy (a gating decision, not a preference). The package supports Tailwind v3.0–v3.4 only. If your roadmap includes a Tailwind v4 migration in the next 12 months, adopting this now means adopting a dependency you will likely have to remove or fork. PMs should force this question before engineering starts.

When to Consider This Package

Consider it when all of the following hold:

  • You are on Tailwind CSS v3.x and v4 is not on the near-term roadmap (or upstream tailwind-merge has a v4 story this port can follow).
  • Styling is authored server-side in PHP — Blade/component libraries, Livewire, mail/PDF builders — where the JS tailwind-merge is simply not available.
  • You have (or want) a composable component system where consumers pass classes in and expect them to win over defaults.
  • Your tailwind.config.js is mostly default. The more custom class groups, renamed scales, plugin utilities, or prefixes you have, the more PHP-side config you must hand-maintain in parallel.
  • You accept a single-maintainer, ~140-star, 0-dependent dependency. MIT means forking is legally trivial; the real question is whether you have someone to own a fork.
  • You are willing to adopt the tailwind-merge-laravel wrapper for Laravel projects rather than hand-wiring the core package.

Look elsewhere (or build/wait) when:

  • Tailwind v4 is imminent. This is a hard stop; the utility semantics and CSS-first config change the problem substantially.
  • Your config is heavily customized. Two sources of truth for design tokens is a silent-correctness hazard — merges will succeed and produce wrong output, which is worse than failing loudly.
  • You need runtime JS-side merging — use the original tailwind-merge.
  • You need a vendored, SLA-backed, or security-audited dependency. There is no commercial support here.
  • The problem is actually CSS specificity discipline. If your teams are fighting !important because the component contract is unclear, a merger is a painkiller, not the fix.

How to Pitch It (Stakeholders)

To executives (30 seconds): Our PHP-rendered UI — components, emails, PDFs — has a recurring class-collision problem that creates visual bugs and support tickets and that engineers keep half-solving by hand. This is a small, MIT-licensed, single-purpose utility that solves it definitively, with no infrastructure, no hosting, and no vendor contract. Cost is one Composer line; the main caveat is that it only covers Tailwind v3, so we should confirm our styling upgrade timeline before committing.

To engineering leadership (2 minutes): It is a faithful PHP port of the widely-used JS tailwind-merge, framework-agnostic, stateless, PHP 8.1+, with an optional PSR-16 cache and a fluent config factory. Integration is a single merge() call behind a thin internal ClassMerger interface so we are not spread across the codebase if we swap it out. Real risks are narrow but real: (1) it is pinned to Tailwind v3.0–v3.4, (2) our custom Tailwind config must be mirrored in PHP, creating config drift, and (3) it is a single-maintainer project with 140 stars — budget for a possible fork. Mitigations: wrap it, add a fixture test suite of our own real class strings targeting arbitrary values/variants (where upstream bugs have historically landed), and gate adoption on the Tailwind v4 question.

To design-system / frontend stakeholders: This lets components accept overrides reliably, which means fewer !important escalations and a clearer contract for how consumers style our components. It does not change how anyone writes Tailwind — it just makes the last class win, deterministically.

The decision we are asking for: Approve a time-boxed spike (one engineer, ~1 week) that answers three questions — Tailwind v4 timeline, how much of our config is non-default, and whether the wrapper's release cadence tracks the core — before we commit to adoption.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
roundly-consulting/kubernetes-api-for-laravel
roundly-consulting/plausible-for-laravel
gvp/gvp-laravel-template
metasyncsite/laravel-metasync-client
roundly-consulting/onboarding-for-laravel
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo