shawnveltman / livewire-3-property-updater
A package to update Livewire 2 computed properties to use the Livewire 3 syntax
Requires
- php: ^8.1|^8.2
- illuminate/contracts: ^10.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.8
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-11-08 14:32:38 UTC
README
In Livewire 2, a computed property "foo" would be defined like this:
public function getFooProperty() { return 'bar'; }
In Livewire 3, the same property would be defined like this:
#[Computed] public function foo() { return 'bar'; }
This package automates that update in your Livewire components folder.
Installation
You can install the package via composer:
composer require --dev shawnveltman/livewire-3-property-updater
You can publish the config file with:
php artisan vendor:publish --tag="livewire-3-property-updater-config"
This is the contents of the published config file:
return [ 'start_directory' => 'app/Livewire', // Defaulting to the app directory, but users can change this. 'disk' => 'base_path', 'method_name_style' => 'snake_case', // StudlyCase or snake_case ];
Two notes on this. First and foremost, the package expects you to have a disk called 'base_path' set up (typically in config/filesystems.php) which points to the base path of the app.
'base_path' => [
'driver' => 'local',
'root' => base_path(),
],
Second - I'm the kind of monster that GREATLY prefers snake_case for method names, so that's the default, but it's easy enough to change it to StudlyCase if that's your preference
Usage for updating computed properties
php artisan shawnveltman:livewire-3-property-updater
Check For Invalid Attempts To Set Property To Null in Livewire 3
In Livewire 3, setting a computed property to null will cause an error. After updating, you might find instances in your code where properties are explicitly set to null. This command automates the process of identifying and updating these instances to use unset instead.
When running this command, it'll scan the Livewire components in your specified directory and look for computed properties being set to null. It will replace these instances with the unset function, preventing potential errors in Livewire 3.
Usage for checking null assignments
php artisan shawnveltman:livewire-null-property-updater
Identify Dispatch Patterns in Livewire
The shawnveltman:dispatch-identifier command scans your Livewire components for specific dispatch patterns. It's especially useful when identifying or refactoring certain dispatch() method usages in Livewire.
The command filters out dispatches with named arguments and presents an output of file paths with the line numbers where the dispatch() method matches the targeted pattern.
Usage for identifying dispatch patterns
php artisan shawnveltman:dispatch-identifier
Testing
composer test
Credits
License
The MIT License (MIT). Please see License File for more information.