Answer the question
In order to leave comments, you need to log in
How to add no more than 4 identical values in a specific table in Laravel Faker?
Good day!
I generate users through a faker
$factory->define(Users::class, function (Faker $faker) {
$teamIds = Team::pluck('id')->toArray();
return [
'id_team' => $faker->randomElement($teamIds),
'name' => $faker->name,
'photo' => $faker->image('/tmp', 400, 400, 'cats'),
'role' => rand(0,1)
];
});
Answer the question
In order to leave comments, you need to log in
database/seeds/TeamSeeder.php
factory(Team::class, 3)->create()->each(function($team) {
$team->users()->saveMany(factory(Users::class, 5)->make());
});
// Roles
$admin_ids = collect(range(1, Users::count()))->random(5)->toArray();
Users::whereIn('id', $admin_ids)->update(['role' => 1]);
You need to generate teams first, and already add participants to the teams,
you do the opposite
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question