sembradora de carrera elocuente
php artisan db:seed --class=UserSeeder
Relieved Raccoon
php artisan db:seed --class=UserSeeder
//create 10 users
factory(User::class, 10)->create()->each(function ($user) {
//create 5 posts for each user
factory(Post::class, 5)->create(['user_id'=>$user->id]);
});
factory(User::class, 10)->create()->each(function ($user) {
$user->posts()->saveMany(factory(Posts::class, 5)->make());
});
how to seed relational database using factory
use App\Models\User;
/**
* Run the database seeders.
*
* @return void
*/
public function run()
{
User::factory()
->count(50)
->hasPosts(1)
->create();
}