Look Up Table For Use in a Seed File

Posted 1 month 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.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.