rector/rector-laravel
Community Rector extension to automate Laravel upgrades. Adds Laravel and first-party package rules (e.g., Cashier, Livewire), with version-based set providers that detect your composer.json or manual level sets to apply the right refactors for your target Laravel version.
LaravelLevelSetList::UP_TO_LARAVEL_130), enabling incremental adoption without forcing full migrations. This fits well with strategic tech debt reduction in large codebases.blank()/filled() helpers) with configurable rules (e.g., RouteActionCallableRector), allowing teams to tailor transformations to their needs.composer require --dev driftingly/rector-laravel) and minimal config (e.g., LaravelSetProvider for auto-detection or explicit sets like LARAVEL_STATIC_TO_INJECTION).--dry-run flag. Ideal for pre-merge validation of refactors.LARAVEL_FACTORIES improve IDE tooling (e.g., autocompletion for factories), reducing manual maintenance overhead.WhereToWhereLikeRector) require database-specific config (USING_POSTGRES_DRIVER), risking incorrect refactors if misconfigured. Mitigation: Test in a staging environment first.rector process in small batches with versioned commits.ResponseHelperCallToJsonResponseRector) may conflict with team conventions. Mitigation: Review rules before bulk application.LARAVEL_CODE_QUALITY)?UseForwardsCallsTraitRector).RemoveDumpDataDeadCodeRector)?LARAVEL_COLLECTION optimizations) improve runtime performance, or are they purely syntactic?LARAVEL_TYPE_DECLARATIONS.rector/rector core instead).rector process --dry-run with targeted sets (e.g., LaravelLevelSetList::UP_TO_LARAVEL_110) to identify high-risk files.rector process --diff to preview changes.LARAVEL_ARRAYACCESS_TO_METHOD_CALL).git commit -m "Apply Rector: Laravel 11 Facade updates" for traceability.ClassNotFoundException from LARAVEL_CONTAINER_STRING_TO_FULLY_QUALIFIED_NAME).LaravelLevelSetList for version-specific rules).rector/rector).WhereToWhereLikeRector may require SQL adjustments if migrating between DBMS (e.g., MySQL → PostgreSQL).| Phase | Rules/Sets | Priority | Validation |
|---|---|---|---|
| Safety-Critical | LARAVEL_CONTAINER_STRING_TO_FULLY_QUALIFIED_NAME, LARAVEL_FACADE_ALIASES_TO_FULL_NAMES |
High | Test all service bindings |
| Dependency Injection | LARAVEL_STATIC_TO_INJECTION |
High | Verify DI container resolution |
| API/Query Changes | LARAVEL_ELOQUENT_MAGIC_METHOD_TO_QUERY_BUILDER, WhereToWhereLikeRector |
Medium | Test all database queries |
| Code Quality | LARAVEL_CODE_QUALITY, LARAVEL_TYPE_DECLARATIONS |
Low | Static analysis (PHPStan) |
| Opinionated | ResponseHelperCallToJsonResponseRector, EmptyToBlankAndFilledFuncRector |
Low | Manual review |
| Testing | LARAVEL_TESTING |
Medium | Re-run test suite |
rector/rector-laravel updates.composer outdated to monitor for new rule versions.composer make:rule for project-specific refactors.git revert for bulk changes).ClassNotFoundException: Fix with composer dump-autoload.MethodNotFoundException: Check Laravel version compatibility.rector.php (e.g., @ignoreNext annotations).rector process --verbose and check Rector’s issue tracker for known bugs.abort() with `abort_ifHow can I help you explore Laravel packages today?