Looking to hire Laravel developers? Try LaraJobs

laravel-factory-refactor maintained by wadakatu

Description
Refactor the style of factory call from helper to static method for Laravel 8.x.
Last update
2025/06/29 06:50 (dev-main)
License
Downloads
108

Comments
comments powered by Disqus

Laravel-Factory-Refactor

GitHub release (latest by date) Packagist PHP Version Support License

This package will help you to refactor the style of factory call from helper to static method for Laravel 10.x, 11.x, 12.x..

With this package, you can save plenty of time and focus on other important things.

Installation

Install the package via composer:

composer require wadakatu/laravel-factory-refactor --dev

How to Use

To refactor the style of factory call from helper to static method, run the artisan command:

php artisan refactor:factory

Options

By default, all factory call under tests/ directory are the target of refactoring.

If you want to change the target directory, you can do that by using the --dir option.

php artisan refactor:factory --dir tests/Feature

By default, Tests\\ namespace is the target of refactoring.

If you want to change the target namespace, you can do that by using the --namespace option.

php artisan refactor:factory --dir app/Models --namespace App\\Models

Example

Before

        factory(User::class)->make();
        factory(App\Models\User::class)->make();
        factory(User::class, 10)->make();
        factory(App\Models\User::class, 10)->make();
        factory($model)->make();
        factory(User::class, $count['user'])->make();

After

        User::factory()->make();
        App\Models\User::factory()->make();
        User::factory()->count(10)->make();
        App\Models\User::factory()->count(10)->make();
        $model::factory()->make();
        User::factory()->count($count['user'])->make();

License

The MIT License (MIT). Please see license file for more information.