s1k3/livewire-v4-patch
Dev-only Laravel tool to convert Livewire v4 class components into Model-Focused Components (MFC). Provides an Artisan command to convert single components or whole folders, with options to keep originals, generate JS/CSS, exclude directories, and disable Pint formatting.
This package will work with PHP >= 8.2 with CURL enabled.
To install this library follow the following steps:
composer require --dev s1k3/livewire-v4-patch
php artisan vendor:publish --provider="LivewireV4\\LivewireV4PatchServiceProvider"
Configuration Options
| Key | Type | Default | Description |
|---|---|---|---|
| excluded_directories | array | [] | Array of directory names to exclude from Livewire component generation |
| class_component_path | string | base_path('app/Livewire') | Path where Livewire class components are stored |
| mfc_component_path | string | resource_path('views/components') | Path for Model-Focused Components (MFC) |
| create_js | boolean | false | Whether to create JavaScript files alongside components |
| create_css | boolean | false | Whether to create CSS files alongside components |
| global_css | boolean | false | Whether to use global CSS instead of component-specific CSS |
| emoji | boolean | false | Whether to use emoji in generated component output |
php artisan convert-class-to:mfc <Path/of/the/component.php>
All paths are being calculated from class_component_path. For example if your compoent is in app/Livewire/Posts/Create.php then your command will be
php artisan convert-class-to:mfc Posts/Create.php
If you want to convert a full directory for example, if Posts have three components
And you want to convert them all just pass the folder name in the command
php artisan convert-class-to:mfc Posts
Please Note that this will delete old class component files and view files
To keep the old component files and view files --keep-class-files option needs to be used.
php artisan convert-class-to:mfc <path/of/the/file/directory> --keep-class-files
In that case, class and view files needs to be removed manually
By deafult, every file created will be formatted using pint but in case if you want to disable that you need to use this flag --without-pint-formatting
php artisan convert-class-to:mfc <path/of/the/file/directory> --without-pint-formatting
After Conversions you might have to clear all the caches and autoload everything.
php artisan optimize:clear
After Conversions you might have to clear all the caches and autoload everything.
php artisan optimize:clear
composer dump-autoload
composer install --optimize-autoloader
If those command still doesn't work then delete composer.lock and vendor/ directory after that install all the packages
composer install
How can I help you explore Laravel packages today?