{"id":16817492,"url":"https://github.com/driftingly/rector-laravel","last_synced_at":"2026-03-05T20:57:56.101Z","repository":{"id":38197111,"uuid":"349255032","full_name":"driftingly/rector-laravel","owner":"driftingly","description":"Rector upgrades rules for Laravel","archived":false,"fork":false,"pushed_at":"2026-03-03T11:59:18.000Z","size":1676,"stargazers_count":1175,"open_issues_count":29,"forks_count":94,"subscribers_count":16,"default_branch":"main","last_synced_at":"2026-03-03T14:31:59.742Z","etag":null,"topics":["ast","instant-upgrades","laravel","php","rector","rules"],"latest_commit_sha":null,"homepage":"http://getrector.org","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/driftingly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-03-19T00:29:30.000Z","updated_at":"2026-03-03T11:27:46.000Z","dependencies_parsed_at":"2025-12-03T09:04:28.106Z","dependency_job_id":null,"html_url":"https://github.com/driftingly/rector-laravel","commit_stats":{"total_commits":282,"total_committers":35,"mean_commits":8.057142857142857,"dds":0.6808510638297872,"last_synced_commit":"b680c0f01111e91700256a382c4759f2bbf5b238"},"previous_names":[],"tags_count":79,"template":false,"template_full_name":null,"purl":"pkg:github/driftingly/rector-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/driftingly%2Frector-laravel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/driftingly%2Frector-laravel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/driftingly%2Frector-laravel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/driftingly%2Frector-laravel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/driftingly","download_url":"https://codeload.github.com/driftingly/rector-laravel/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/driftingly%2Frector-laravel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30149906,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T16:58:46.102Z","status":"ssl_error","status_checked_at":"2026-03-05T16:58:45.706Z","response_time":93,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","instant-upgrades","laravel","php","rector","rules"],"created_at":"2024-10-13T10:47:21.773Z","updated_at":"2026-03-05T20:57:56.092Z","avatar_url":"https://github.com/driftingly.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"./banner.png\" style=\"width: 100%\" /\u003e\n\n# Rector Rules for Laravel\n\n[![Tests](https://github.com/driftingly/rector-laravel/actions/workflows/tests.yaml/badge.svg)](https://github.com/driftingly/rector-laravel/actions/workflows/tests.yaml)\n[![Code Analysis](https://github.com/driftingly/rector-laravel/actions/workflows/code_analysis.yaml/badge.svg)](https://github.com/driftingly/rector-laravel/actions/workflows/code_analysis.yaml)\n[![Packagist Downloads](https://img.shields.io/packagist/dm/driftingly/rector-laravel)](https://packagist.org/packages/driftingly/rector-laravel/stats)\n[![Packagist Version](https://img.shields.io/packagist/v/driftingly/rector-laravel)](https://packagist.org/packages/driftingly/rector-laravel)\n\n## Available Rules\n\nSee all available Laravel rules [here](/docs/rector_rules_overview.md). This list includes even the rules that are not yet released, but are available under the `dev-main` branch.\n\nYou can also find the released rules on the Rector [Find Rule](https://getrector.com/find-rule?activeRectorSetGroup=laravel) page.\n\n## Install\n\nThis package is a [Rector](https://github.com/rectorphp/rector) extension developed by the Laravel community.\n\nRules for additional first party packages are included as well e.g. Cashier and Livewire.\n\nInstall as a dev dependency:\n\n```bash\ncomposer require --dev driftingly/rector-laravel\n```\n\n## Automate Laravel Upgrades\n\nTo automatically apply the correct rules depending on the version of Laravel (or other packages) you are currently on (as detected in the `composer.json`), use the following:\n\n```php\n\u003c?php declare(strict_types=1);\n\nuse Rector\\Config\\RectorConfig;\nuse RectorLaravel\\Set\\LaravelSetProvider;\n\nreturn RectorConfig::configure()\n    -\u003ewithSetProviders(LaravelSetProvider::class)\n    -\u003ewithComposerBased(laravel: true, /** other options */);\n```\n\n### Manual Configuration\n\nTo manually add a version set to your config, use `RectorLaravel\\Set\\LaravelLevelSetList` and pick the constant that matches your target version.\nSets for higher versions include sets for lower versions.\n\n```php\n\u003c?php declare(strict_types=1);\n\nuse Rector\\Config\\RectorConfig;\nuse RectorLaravel\\Set\\LaravelLevelSetList;\n\nreturn RectorConfig::configure()\n    -\u003ewithSets([\n        LaravelLevelSetList::UP_TO_LARAVEL_110,\n    ]);\n```\n\nThe sets in `RectorLaravel\\Set\\LaravelSetList` only contain changes related to a specific version upgrade.\nFor example, the rules in `LaravelSetList::LARAVEL_110` apply when upgrading from Laravel 10 to Laravel 11.\n\n## Additional Sets\n\nTo improve different aspects of your code, use the sets in `RectorLaravel\\Set\\LaravelSetList`.\n\n```php\n\u003c?php declare(strict_types=1);\n\nuse Rector\\Config\\RectorConfig;\nuse RectorLaravel\\Set\\LaravelSetList;\n\nreturn RectorConfig::configure()\n    -\u003ewithSets([\n        LaravelSetList::LARAVEL_CODE_QUALITY,\n        LaravelSetList::LARAVEL_COLLECTION,\n        ...\n    ]);\n```\n\n| Set                                                                                                                                                                                         | Purpose                                                                                                                                                                                                                                          |\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [LaravelSetList::LARAVEL_ARRAYACCESS_TO_METHOD_CALL](https://github.com/driftingly/rector-laravel/blob/main/config/sets/laravel-arrayaccess-to-method-call.php)                             | Converts uses of things like `$app['config']` to `$app-\u003emake('config')`.                                                                                                                                                                         |\n| [LaravelSetList::LARAVEL_ARRAY_STR_FUNCTION_TO_STATIC_CALL](https://github.com/driftingly/rector-laravel/blob/main/config/sets/laravel-array-str-functions-to-static-call.php)              | Converts most string and array helpers into Str and Arr Facades' static calls.\u003cbr/\u003e\u003chttps://laravel.com/docs/12.x/facades#facades-vs-helper-functions\u003e                                                                                             |\n| [LaravelSetList::LARAVEL_CODE_QUALITY](https://github.com/driftingly/rector-laravel/blob/main/config/sets/laravel-code-quality.php)                                                         | Replaces magical call on `$this-\u003eapp[\"something\"]` to standalone variable with PHPDocs.                                                                                                                                                          |\n| [LaravelSetList::LARAVEL_COLLECTION](https://github.com/driftingly/rector-laravel/blob/main/config/sets/laravel-collection.php)                                                             | Improves the usage of Laravel Collections by using simpler, more efficient, or more readable methods.                                                                                                                                            |\n| [LaravelSetList::LARAVEL_CONTAINER_STRING_TO_FULLY_QUALIFIED_NAME](https://github.com/driftingly/rector-laravel/blob/main/config/sets/laravel-container-string-to-fully-qualified-name.php) | Changes the string or class const used for a service container make call.\u003cbr/\u003e\u003chttps://laravel.com/docs/12.x/container#the-make-method\u003e                                                                                                            |\n| [LaravelSetList::LARAVEL_ELOQUENT_MAGIC_METHOD_TO_QUERY_BUILDER](https://github.com/driftingly/rector-laravel/blob/main/config/sets/laravel-eloquent-magic-method-to-query-builder.php)     | Transforms magic method calls on Eloquent Models into corresponding Query Builder method calls.\u003cbr/\u003e\u003chttps://laravel.com/docs/12.x/eloquent\u003e                                                                                                       |\n| [LaravelSetList::LARAVEL_FACADE_ALIASES_TO_FULL_NAMES](https://github.com/driftingly/rector-laravel/blob/main/config/sets/laravel-facade-aliases-to-full-names.php)                         | Replaces Facade aliases with full Facade names.\u003cbr/\u003e\u003chttps://laravel.com/docs/12.x/facades#facade-class-reference\u003e                                                                                                                                 |\n| [LaravelSetList::LARAVEL_FACTORIES](https://github.com/driftingly/rector-laravel/blob/main/config/sets/laravel-factories.php)                                                               | Makes working with Laravel Factories easier and more IDE friendly.                                                                                                                                                                               |\n| [LaravelSetList::LARAVEL_IF_HELPERS](https://github.com/driftingly/rector-laravel/blob/main/config/sets/laravel-if-helpers.php)                                                             | Replaces `abort()`, `report()`, `throw` statements inside conditions with `abort_if()`, `report_if()`, `throw_if()` function calls.\u003cbr/\u003e\u003chttps://laravel.com/docs/12.x/helpers#method-abort-if\u003e                                                    |\n| [LaravelSetList::LARAVEL_LEGACY_FACTORIES_TO_CLASSES](https://github.com/driftingly/rector-laravel/blob/main/config/sets/laravel-legacy-factories-to-classes.php)                           | Migrates Eloquent legacy model factories (with closures) into class based factories.\u003cbr/\u003e\u003chttps://laravel.com/docs/8.x/releases#model-factory-classes\u003e                                                                                             |\n| [LaravelSetList::LARAVEL_STATIC_TO_INJECTION](https://github.com/driftingly/rector-laravel/blob/main/config/sets/laravel-static-to-injection.php)                                           | Replaces Laravel's Facades with Dependency Injection.\u003cbr/\u003e\u003chttps://tomasvotruba.com/blog/2019/03/04/how-to-turn-laravel-from-static-to-dependency-injection-in-one-day/\u003e\u003cbr/\u003e\u003chttps://laravel.com/docs/12.x/facades#facades-vs-dependency-injection\u003e |\n| [LaravelSetList::LARAVEL_TESTING](https://github.com/driftingly/rector-laravel/blob/main/config/sets/laravel-testing.php)                                                                     | Improves Laravel testing by converting deprecated methods and adding better assertions.                                                                                                                                                               |\n| [LaravelSetList::LARAVEL_TYPE_DECLARATIONS](https://github.com/driftingly/rector-laravel/blob/main/config/sets/laravel-type-declarations.php)                                                 | Adds type hints and generic return types to improve Laravel code type safety.                                                                                                                                                                        |\n\n## Configurable Rules\n\nThese rules require configuration and must be added manually to your `rector.php` file.\n\n```php\n\u003c?php declare(strict_types=1);\n\nuse Rector\\Config\\RectorConfig;\nuse RectorLaravel\\Rector\\FuncCall\\RemoveDumpDataDeadCodeRector;\n\nreturn RectorConfig::configure()\n    -\u003ewithConfiguredRule(RemoveDumpDataDeadCodeRector::class, [\n        'dd', 'dump', 'var_dump'\n    ]);\n```\n\n| Rule | Description |\n|------|-------------|\n| [RemoveDumpDataDeadCodeRector](https://github.com/driftingly/rector-laravel/blob/main/src/Rector/FuncCall/RemoveDumpDataDeadCodeRector.php) | Removes debug function calls like `dd()`, `dump()`, etc. from code. Configure with an array of function names to remove (default: `['dd', 'dump']`). |\n| [RouteActionCallableRector](https://github.com/driftingly/rector-laravel/blob/main/src/Rector/StaticCall/RouteActionCallableRector.php) | Converts route action strings like `'UserController@index'` to callable arrays `[UserController::class, 'index']`. Configure with `NAMESPACE` for controller namespace and `ROUTES` for file-specific namespaces. |\n| [WhereToWhereLikeRector](https://github.com/driftingly/rector-laravel/blob/main/src/Rector/MethodCall/WhereToWhereLikeRector.php) | Converts `where('column', 'like', 'value')` to `whereLike('column', 'value')` calls. Configure with `USING_POSTGRES_DRIVER` boolean to handle PostgreSQL vs MySQL differences. |\n\n## Opinionated Rules\n\nThese rules are more opinionated and are not included in any sets by default.\n\n```php\n\u003c?php declare(strict_types=1);\n\nuse Rector\\Config\\RectorConfig;\nuse RectorLaravel\\Rector\\MethodCall\\ResponseHelperCallToJsonResponseRector;\n\nreturn RectorConfig::configure()\n    -\u003ewithRules([\n        ResponseHelperCallToJsonResponseRector::class,\n    ]);\n```\n\n| Rule | Description |\n|------|-------------|\n| [RemoveModelPropertyFromFactoriesRector](https://github.com/driftingly/rector-laravel/blob/main/src/Rector/Class_/RemoveModelPropertyFromFactoriesRector.php) | Removes the `$model` property from Factories. |\n| [ResponseHelperCallToJsonResponseRector](https://github.com/driftingly/rector-laravel/blob/main/src/Rector/MethodCall/ResponseHelperCallToJsonResponseRector.php) | Converts `response()-\u003ejson()` to `new JsonResponse()`. |\n| [MinutesToSecondsInCacheRector](https://github.com/driftingly/rector-laravel/blob/main/src/Rector/StaticCall/MinutesToSecondsInCacheRector.php) | Change minutes argument to seconds in cache methods. |\n| [UseComponentPropertyWithinCommandsRector](https://github.com/driftingly/rector-laravel/blob/main/src/Rector/MethodCall/UseComponentPropertyWithinCommandsRector.php) | Use `$this-\u003ecomponents` property within commands. |\n| [UseForwardsCallsTraitRector](https://github.com/driftingly/rector-laravel/blob/main/src/Rector/Class_/UseForwardsCallsTraitRector.php) | Replaces the use of `call_user_func` and `call_user_func_array` method with the CallForwarding trait. |\n| [EmptyToBlankAndFilledFuncRector](https://github.com/driftingly/rector-laravel/blob/main/src/Rector/Empty_/EmptyToBlankAndFilledFuncRector.php) | Converts `empty()` to `blank()` and `filled()` |\n\n## Creating New Rules\n\nYou can create a new rule using the composer script:\n\n```bash\ncomposer make:rule -- YourRuleName\n```\n\nThis will generate a new rule class in `src/Rector/` along with the corresponding test files.\n\n### Command Options\n\n- `--configurable` or `-c`: Create a configurable rule that implements `ConfigurableRectorInterface`\n\n### Directory Structure\n\nYou can specify a subdirectory structure by including slashes in the rule name:\n\n```bash\ncomposer make:rule -- If_/ConvertIfToWhen\n```\n\nThis will create a rule in the `src/Rector/If_/` directory with the namespace `RectorLaravel\\Rector\\If_`.\n\nRemember to always add `--` before the arguments when using the composer script. This separator tells Composer that the following arguments should be passed to the script rather than being interpreted as Composer arguments.\n\n## Contributors\n\nThank you everyone who works so hard on improving this package:\n\n- [@TomasVotruba](https://github.com/TomasVotruba)\n- [@peterfox](https://github.com/peterfox)\n- [@GeniJaho](https://github.com/GeniJaho)\n- [@driftingly](https://github.com/driftingly)\n- [@calebdw](https://github.com/calebdw)\n- [All Contributors](https://github.com/driftingly/rector-laravel/graphs/contributors)\n\nA special thank you to [Caneco](https://github.com/caneco) for designing the logo!\n\n## Hire The Rector Team\n\nRector is a tool that [we develop](https://getrector.com/) and share for free, so anyone can automate their refactoring. But not everyone has dozens of hours to understand complexity of abstract-syntax-tree in their own time. **That's why we provide commercial support - to save your time**.\n\nWould you like to apply Rector on your code base but don't have time for the struggle with your project? [Hire the Rector team](https://getrector.com/contact) to get there faster.\n\n## Learn Rector Faster\n\nNot everyone has time to understand Rector and AST complexity. You can speed up the process by reading the book [The Power of Automated Refactoring](https://leanpub.com/rector-the-power-of-automated-refactoring). Not only will it help you learn and understand Rector but it supports the project as well.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdriftingly%2Frector-laravel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdriftingly%2Frector-laravel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdriftingly%2Frector-laravel/lists"}