Reputation: 1650
I'm new in Laravel and I want to generate fake data for the table Users. Right know this is working fine:
UserFactory.php
$factory->define(App\User::class, function (Faker $faker) {
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret
'remember_token' => str_random(10),
];
});
UsersTableSeeder.php
public function run() {
factory(App\User::class, 5)->create();
}
DatabaseSeeder.php
public function run() {
$this->call(UsersTableSeeder::class);
}
The previous code generates 5 rows in the User table and it is OK.
Now I would like to generate one more extra user ( in addition of the 5 rows already generated) with fixed fields like:
return [
'name' => 'user test',
'email' => '[email protected]',
'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret
'remember_token' => str_random(10),
];
Where I have to put the above code? Do I have to generate a new UserFactory?
Upvotes: 3
Views: 1580
Reputation:
You can put the following code in your UsersTableSeeder.php
s run()
method right after your existing code:
factory(App\User::class)->create([
'name' => 'user test',
'email' => '[email protected]',
'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret
'remember_token' => str_random(10),
]);
You could also use 'password' => bcrypt(USERPASSWORDHERE),
to create an encrypted string of USERPASSWORDHERE
Upvotes: 4