Skip to content

Commit

Permalink
improved ConversationSeeder
Browse files Browse the repository at this point in the history
  • Loading branch information
myckhel committed Jul 29, 2021
1 parent c722710 commit f6c42d1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Database/Seeders/ConversationSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ public function run()
$faker = Faker::create();
$users = $userModel::pluck($user_key)->toArray();
$conversationModel::factory()->count($faker->numberBetween(min(100, count($users)), count($users)))
->hasParticipants($faker->numberBetween(2, 4), fn ($attributes, $conversation) =>
->hasParticipants($faker->numberBetween(3, 5), fn ($attributes, $conversation) =>
[
'user_id' => $faker->randomElement($users),
'user_id' => $faker->randomElement(
collect($users)->filter(fn ($id) => $id != $conversation->user_id)
),
'conversation_id' => $conversation->id,
]
)
Expand All @@ -34,7 +36,10 @@ public function run()
'conversation_id' => $conversation->id,
'user_id' => $faker->randomElement([
$conversation->author->id,
$conversation->query()->whereNotParticipant($conversation->author)
$conversation
->query()
->whereNotParticipant($conversation->author)
->inRandomOrder()
->first()->user_id,
])
]
Expand Down

0 comments on commit f6c42d1

Please sign in to comment.