so which of your factory is also creating users?
May 22, 2024
7
Level 8
Help with Unifid database Seeder! Eloquent
I started with this but too many users are created
\App\Models\User::factory()->create([
'name' => 'Admin',
'email' => '[email protected]',
'password' => bcrypt('secret'),
]);
\App\Models\User::factory()->create([
'name' => 'Volunteer',
'email' => '[email protected]',
'password' => bcrypt('secret'),
]);
User::factory()->count(48)->create();
Detail::factory()->count(40)->create();
Host::factory()->count(30)->create();
Contact::factory()->count(40)->create();
Message::factory()->count(40)->create();
So using GPT I got to this, but still too many users are created, should I be concerned or should I just continue since the data is there anyway so it doesn't really matter. (Really need to learn how to handle dummy data like a PRO)
\App\Models\User::factory()->create([
'name' => 'Admin',
'email' => '[email protected]',
'password' => bcrypt('secret'),
]);
\App\Models\User::factory()->create([
'name' => 'Volunteer',
'email' => '[email protected]',
'password' => bcrypt('secret'),
]);
User::factory()->count(48)->create();
$users = User::all();
Detail::factory()->count(40)->make()->each(function ($host) use ($users) {
$host->user_id = $users->random()->id;
$host->save();
});
Host::factory()->count(10)->make()->each(function ($host) use ($users) {
$host->user_id = $users->random()->id;
$host->save();
});
Contact::factory()->count(20)->make()->each(function ($contact) use ($users) {
$contact->sender_id = $users->random()->id;
$contact->receiver_id = $users->random()->id;
$contact->save();
});
$contacts = Contact::all();
// Create messages for each contact
Message::factory()->count(40)->make()->each(function ($message) use ($contacts) {
$message->contact_id = $contacts->random()->id;
$message->save();
});
Please or to participate in this conversation.