AlexanderKim
1 year ago
434
4
Laravel

How to use faker in Seeder?

Posted 1 year ago by AlexanderKim

Here's my seeder:

    public function run()
    {
        // create administrator
        User::create([
            'user_name' => 'Administrator',
            'user_email' => '[email protected]',
            'user_address' => '123123 34',
            'user_phone' => '+123123213',
            'password' => bcrypt('test')
        ]);

        // generating users for testing purposes with faker
        factory(App\User::class, 10)->make();
    }

UserFactory.php:

$factory->define(App\User::class, function (Faker $faker) {
    return [
        'user_name' => $faker->name,
        'user_email' => $faker->unique()->safeEmail,
        'user_address' => $faker->sentence(5),
        'user_phone' => '123',
        'password' => 'y$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret
        'remember_token' => str_random(10),
    ];
});

When i run php artisan db:seed, it seeds just my manually created user "Administrator", but factory doesn't run.

Also where i can check all $faker properties? Like name/email/sentence, couldn't find anything in documentation.

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