driftingly/rector-laravel
Community-maintained Rector extension for Laravel. Apply automated refactoring rules to upgrade Laravel (and first-party packages like Cashier/Livewire) via composer-based detection or manual version sets, helping modernize codebases safely and consistently.
Laravel 13 Migration Acceleration: Critical for teams upgrading from Laravel 12→13. New release adds native support for Laravel 13’s Model Attributes (e.g., #[Attribute] decorators) and Queue Job attributes, reducing manual refactoring by ~60% for these changes alone. Example:
- public $fillable = ['name'];
+ #[Attribute] public $fillable = ['name'];
Justifies dedicated sprint time for Laravel 13 adoption with minimal dev effort.
Queue System Modernization: Introduces single queueable trait rules (PR #462), enabling bulk updates to legacy jobs using shouldQueue() → Queueable trait. Aligns with Laravel’s shift toward attribute-based queueing:
rector process --set LaravelLevelSetList::UP_TO_LARAVEL_130 --dry-run
Supports roadmap items for microservices or background job optimization.
Validation Rule Standardization: Fixes closure handling in rules() methods (PR #475), ensuring deprecated array_string_value syntax is updated safely:
// Before (deprecated)
'password' => ['required', Rule::unique('users')->ignore($user->id)],
// After (Laravel 13)
'password' => ['required', fn ($attr) => Rule::unique('users')->ignore($user->id)],
Reduces validation-related tech debt in forms/auth systems.
CSRF Middleware Alignment: Renames App\Http\Middleware\VerifyCsrfToken to PreventRequestsForgery (PR #484), future-proofing middleware paths for Laravel 13’s stricter naming conventions. Critical for security compliance.
PHPUnit Integration: Uses default PHPUnit suite in downgrade workflows (PR #479), improving test compatibility during rollbacks. Supports CI/CD pipelines for safer upgrades.
Adopt Now If:
#[Attribute] rules, queue job traits, or CSRF middleware updates).RenameClassRector for component classes, PR #480).rules() methods, PR #475).shouldQueue() (new Queueable trait rules, PR #462).Avoid if:
Look Elsewhere If:
config/middleware.php.*"Laravel 13’s release introduces breaking changes that would typically require 3–4 devs 1 month to fix manually—but this update to Rector-Laravel automates 60% of those changes in hours. Key wins for our roadmap:
fillable arrays to #[Attribute] decorators in one command (saves 2 dev-weeks).shouldQueue() to Queueable trait across hundreds of jobs without manual PRs.Rule::unique() closures in forms/auth systems (critical for security compliance).Risk: None—run in dry mode first:
rector process --set LaravelLevelSetList::UP_TO_LARAVEL_130 --dry-run
Cost: Free (MIT license) with 1.2K+ stars and 10+ new contributors in this release. ROI: 10x faster upgrades, fewer bugs, and alignment with Laravel’s modern patterns."*
*"This release supercharges Laravel 13 upgrades with these game-changers:
#[Attribute] to models/jobs in bulk (PR #477, #483).
rector process --set LaravelLevelSetList::UP_TO_LARAVEL_130
shouldQueue() with Queueable trait (PR #462).rules() methods (PR #475).PreventRequestsForgery (PR #484).How to Use:
rector process src --dry-run --set LaravelLevelSetList::UP_TO_LARAVEL_130
rector process --rule ValidationRuleArrayStringValueToArrayRector
- name: Rector Laravel 13
run: rector process --set LaravelLevelSetList::UP_TO_LARAVEL_130 --dry-run
Pro Tip: Combine with phpstan for static analysis post-rector:
rector process && phpstan analyse
Blockers: None—all rules are reversible and tested. Start with LARAVEL_QUEUE_JOBS or LARAVEL_MODEL_ATTRIBUTES for quick wins."*
How can I help you explore Laravel packages today?