라라벨 Factory, Seeder 차이 비교

2022. 5. 6. 11:39PHP/Laravel8.X

728x90

Seeder, Factory 사용법 코드 풀버전

https://www.scratchcode.io/difference-between-factory-and-seeders-in-laravel/

Faker library

https://github.com/fzaninotto/Faker

Seeders Factory
Test/fake data 생성
Class Helper function,
Global object
CLI command
> php artisan make:seeder UsersSeeder
Model
> php artisan make:factory PostFactory
    public function run()
    {
        DB::table('users')->insert(
            [
                'name' => Str::random(10),
                'email' => Str::random(10).'@gmail.com',
                'password' => Hash::make('password'),
            ],
            [
                'name' => Str::random(10),
                'email' => Str::random(10).'@gmail.com',
                'password' => Hash::make('password'),
            ],
        );
    }
 
    public function run()
    {
        factory(User::class, 2)->create();
        factory(Post::class, 2)->create();
    }
 

 

 

 

 

 

 

 

 

 

728x90
반응형