当前位置:网站首页>Laravel8 uses faker to call factory to fill data

Laravel8 uses faker to call factory to fill data

2022-06-24 14:27:00 s_ Canned ice

1. Install the population file through the command .

php artisan make:seeder UserSeeder

2. stay database Find our fill file

3. Write the function method in our fill file

// Write seed file ( Use Chinese package )
        $faker = Factory::create('zh_CN');

        // How much test data to fill according to our needs ( I am here 20 So it's filling 20 Data )
        for ($i = 0; $i <= 20; $i++) {
            // Call the model to fill in the data 
            UddModel::create([
                'username' => $faker->name,
                'password' => bcrypt('123456'),]);
//             notes : Add the creation time field in the process of filling data (updated_at) And modify the time field (updated_at) Prevent filling errors 
        }

4. Execute our fill file to generate fill data

php artisan db:seed --class=UserSeeder

原网站

版权声明
本文为[s_ Canned ice]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241244453620.html