php - Laravel: How can i generate two unique seeds in my laravel faker -
i want create 2 unique users in faker. wanna know right way of doing it.
$factory->define(app\user::class, function (faker\generator $faker) { static $password; return [ { 'name' => "person 1", 'email' => "person1@gmail.com", 'password' => $password ?: $password = bcrypt('secret'), 'remember_token' => str_random(10), 'role' => 'super', }, { 'name' => "person 2", 'email' => "person2@gmail.com", 'password' => $password ?: $password = bcrypt('secret'), 'remember_token' => str_random(10), 'role' => 'admin', }, ]; });
this code solved problem
$factory->define(app\user::class, function (faker\generator $faker) { static $password; return [ 'name' => $faker->unique()->randomelement($array = array ('person1','person2')), 'email' => $faker->unique()->randomelement($array = array ('p1@gmail.com','p2@gmail.com')), 'password' => $password ?: $password = bcrypt('secret'), 'remember_token' => str_random(10), 'role' => $faker->unique()->randomelement($array = array ('super','admin')), ]; });
Comments
Post a Comment