牙列缺损
4381 ワード
databaseの下にあるfactoryに入ります
factory(App\Models\Post::class,50)->make()
Laravelでfakerを使用してデータを埋め込む
$factory->define(User::class, function (Faker $faker) {
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
];
});
$factory->define(\App\Models\Post::class, function (Faker $faker) {
return [
'title' => $faker->sentence(6),
'content' => $faker->paragraph(10),
];
});
tinker
php artisan tinker
factory(App\Models\Post::class,50)->make()
// create
Laravelでfakerを使用してデータを埋め込む
2017.07.23 21:29:09文字55読解402
1.次のコードをdatabase\factories\ModelFactory.php
に追加//
$factory->define(App\Post::class, function (Faker\Generator $faker) { return [ 'title' => $faker->sentence(6), 'content' => $faker->paragraph(10) ]; });
Postは、returnに埋め込むデータを設定するテーブルモデルの参照です.https://github.com/fzaninotto/Faker2.端末にphp artisan tinker
を入力してtinkerに入る//
factory(App\Post::class,10)->make() // factory(App\Post::class,10)->create() ## App\Post ,10
//
$factory->define(App\Post::class, function (Faker\Generator $faker) { return [ 'title' => $faker->sentence(6), 'content' => $faker->paragraph(10) ]; });
//
factory(App\Post::class,10)->make() // factory(App\Post::class,10)->create() ## App\Post ,10