### Install Dev Dependencies Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/CONTRIBUTING.md Installs the development dependencies required for the project using Composer. ```bash composer install ``` -------------------------------- ### Install TailwindMerge for Laravel Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/README.md Install the package using Composer. This command fetches and installs the latest version of the TailwindMerge for Laravel package into your project. ```bash composer require gehrisandro/tailwind-merge-laravel ``` -------------------------------- ### Use Tailwind Merge Helper Method in Laravel Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/README.md Provides an example of using the global `twMerge` helper function to merge CSS classes within a Laravel application. This method offers a concise way to perform class merging without needing to import Facades. ```php twMerge('w-10 h-10 rounded-full bg-red-500 bg-blue-500'); // w-10 h-10 rounded-full bg-blue-500 ``` -------------------------------- ### Configure Blade Directive Name Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/README.md Illustrates how to customize the name of the Blade directive used for Tailwind merging in the `config/tailwind-merge.php` file. It provides an example of setting a custom directive name and how to disable it entirely by setting it to `null`. ```php // config/tailwind-merge.php return [ 'blade_directive' => 'customTwMerge', ]; ``` ```php // config/tailwind-merge.php return [ 'blade_directive' => null, ]; ``` -------------------------------- ### Use TailwindMerge in Blade Components Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/README.md Apply TailwindMerge to class attributes within Blade components to automatically merge and resolve conflicting classes. This example shows merging classes for a circular div. ```php // circle.blade.php
twMerge('w-10 h-10 rounded-full bg-red-500') }}>
// your-view.blade.php // output
``` -------------------------------- ### Use Tailwind Merge Blade Directive Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/README.md Shows how to use the custom `@twMerge` Blade directive to merge CSS classes directly within Blade views. It demonstrates merging multiple classes passed as separate arguments or a single string. It also includes examples of how to rename or disable the directive in the configuration file. ```blade @twMerge('w-10 h-10 rounded-full bg-red-500 bg-blue-500') // w-10 h-10 rounded-full bg-blue-500 ``` ```blade // or multiple arguments @twMerge('w-10 h-10 rounded-full bg-red-500', 'bg-blue-500') // w-10 h-10 rounded-full bg-blue-500 ``` -------------------------------- ### Add Custom Class Group for Font Size Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/README.md Demonstrates how to extend Tailwind Merge's merging capabilities by adding custom class groups. This example shows how to add a 'very-large' font size to the 'font-size' group within the `config/tailwind-merge.php` file. ```php // config/tailwind-merge.php return [ 'classGroups' => [ 'font-size' => [ ['text' => ['very-large']] ], ], ]; ``` -------------------------------- ### Merge Classes on Multiple Elements in Blade Components Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/README.md Explains how to merge classes on multiple elements within a single Blade component using `twMergeFor()`. It provides an example of a button component with an SVG icon, showing how to apply classes to both the button and the icon separately. It also highlights the need to use `withoutTwMergeClasses()` on the main attributes bag. ```blade ``` ```blade Click Me ``` ```html ``` -------------------------------- ### Run All Tests Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/CONTRIBUTING.md Executes all tests defined for the project. ```bash composer test ``` -------------------------------- ### Run Unit Tests Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/CONTRIBUTING.md Executes the unit tests for the project using Pest. ```bash composer test:pest ``` -------------------------------- ### Check Types Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/CONTRIBUTING.md Verifies the type hints and type safety within the project's code. ```bash composer test:types ``` -------------------------------- ### Check Code Quality Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/CONTRIBUTING.md Performs a code quality check on the project. ```bash composer test:refactor ``` -------------------------------- ### Lint Code Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/CONTRIBUTING.md Lints the project's code to ensure it adheres to the defined coding style. ```bash composer refactor:lint ``` -------------------------------- ### Publish Configuration File Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/README.md Optionally publish the configuration file to customize package behavior. This makes the `config/tailwind-merge.php` file available for modification. ```bash php artisan vendor:publish --provider="TailwindMerge\Laravel\TailwindMergeServiceProvider" ``` -------------------------------- ### Refactor Code Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/CONTRIBUTING.md Refactors the project's code using Rector, a tool for automatic code refactoring. ```bash composer refactor:rector ``` -------------------------------- ### Configure Tailwind Merge Prefix Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/README.md Explains how to configure a prefix for Tailwind Merge to avoid class name collisions. It shows two methods: setting the prefix directly in the `config/tailwind-merge.php` file or using the `TAILWIND_MERGE_PREFIX` environment variable. ```php // config/tailwind-merge.php return [ 'prefix' => 'tw-', ]; ``` ```env TAILWIND_MERGE_PREFIX=tw- ``` -------------------------------- ### Merge Classes with Different Input Types Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/README.md Shows how to pass class names to the `TailwindMerge::merge` method using strings, arrays, or a combination of both. The method correctly merges classes regardless of the input format. ```php TailwindMerge::merge('h-10 h-20'); // h-20 TailwindMerge::merge(['h-10', 'h-20']); // h-20 TailwindMerge::merge(['h-10', 'h-20'], 'h-30'); // h-30 TailwindMerge::merge(['h-10', 'h-20'], 'h-30', ['h-40']); // h-40 ``` -------------------------------- ### Configure Tailwind Merge Prefix Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/README.md Set a custom prefix for Tailwind Merge using environment variables. This allows for prefixing generated classes if needed. ```env TAILWIND_MERGE_PREFIX=tw- ``` -------------------------------- ### Use Tailwind Merge Facade in Laravel Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/README.md Demonstrates how to use the `TailwindMerge` Facade to merge CSS classes in Laravel applications outside of Blade views. It shows the necessary `use` statement and the method call for merging classes. ```php use TailwindMerge\Laravel\Facades\TailwindMerge; TailwindMerge::merge('w-10 h-10 rounded-full bg-red-500 bg-blue-500'); // w-10 h-10 rounded-full bg-blue-500 ``` -------------------------------- ### Use Tailwind Merge in Laravel Blade Components Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/README.md Demonstrates how to use the `twMerge` method on the `$attributes` bag within Laravel Blade components to merge CSS classes. It shows how to pass additional classes to the component and the resulting HTML output. It also notes the limitation with `$attributes->merge(['class' => '...'])`. ```blade
twMerge('w-10 h-10 rounded-full bg-red-500') }}>
``` ```blade ``` ```html
``` -------------------------------- ### Merge Conflicting Tailwind Classes Source: https://github.com/gehrisandro/tailwind-merge-laravel/blob/main/README.md Demonstrates merging various types of conflicting Tailwind CSS classes using the `TailwindMerge::merge` facade. It handles simple conflicts, breakpoints, dark mode, states, important modifiers, arbitrary values, and non-tailwind classes. ```php use TailwindMerge\Laravel\Facades\TailwindMerge; // conflicting classes TailwindMerge::merge('block inline'); // inline TailwindMerge::merge('pl-4 px-6'); // px-6 // non-conflicting classes TailwindMerge::merge('text-xl text-black'); // text-xl text-black // with breakpoints TailwindMerge::merge('h-10 lg:h-12 lg:h-20'); // h-10 lg:h-20 // dark mode TailwindMerge::merge('text-black dark:text-white dark:text-gray-700'); // text-black dark:text-gray-700 // with hover, focus and other states TailwindMerge::merge('hover:block hover:inline'); // hover:inline // with the important modifier TailwindMerge::merge('!font-medium !font-bold'); // !font-bold // arbitrary values TailwindMerge::merge('z-10 z-[999]'); // z-[999] // arbitrary variants TailwindMerge::merge('[&>*]:underline [&>*]:line-through'); // [&>*]:line-through // non tailwind classes TailwindMerge::merge('non-tailwind-class block inline'); // non-tailwind-class inline ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.