Laravel 5.2 seed specific data array

- 1 answer

Ad

I am trying to seed my database with some specific content to get my application started. I am aware of Faker and how to use it (which I do for my Users). Now I want to fill a table with (alot) of records that are not randomly generated, so not created by Faker.

For example I want to have a table with some (lets say 30) clubs so that I can generate a few hundered users who are member of one of those 30 clubs with $faker->randomElement.

Is there another way then to type this 30 times?

   $club = Club::create(array(
        'name' => 'FC Barcelona',
        'number' => '001',
    ));    

Couldn't find this in the laravel (5.2) docs. Only the Faker is explained.

Thanks

Ad

Answer

Ad

What you can do is creating one array with clubs and seed them and in UsersDatabaseSeeder you can create in loop as many records you want and assign for each of them random club.

EDIT

$clubs = [['prop1'=> 'val1',], ['prop1' => 'val2']];
\DB::table('clubs')->insert($clubs);
Ad
source: stackoverflow.com
Ad