Look Up Table For Use in a Seed File

Posted 5 months ago by xtremer360

I have the following Eloquent call to my database that retrieves 10-12 rows. What I need to do for the purposes of a seeder is assign a value (int 1-100) to each of those rows so that I can declare the chance of one type being used more than the others. So as you can see from this snippet currently in my seed file it will just grab one of the types from the database however I want to give it a look up table to be able to say which types are more likely to be used than the others.

$match = $event->matches()->save(factory(Match::class)->create([
    'match_type_id' => MatchType::inRandomOrder()->first()->id,
]));
private function chance(int $percent)
{
    return rand(0, 100) < $percent;
}

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.