-
Notifications
You must be signed in to change notification settings - Fork 79
Open
Description
At first glance, I tried to create a factory for admin users like so:
$factory('App\User', [
'name' => $faker->userName,
'password' => $faker->password,
]);
$factory('App\User', 'admin_user', [
'admin' => 1,
]);
… But this doesn't work. All the attributes have to be defined again. This was a bit suprising, mainly because Factory::build('App\User', ['admin' => 1]) was doing the job. But I understand, the current behaviour is perfectly fine, short names aren't at all about extending.
So, I tried this:
$factory('App\User', 'admin_user', Factory::attributesFor('App\User', [
'admin' => 1,
]));
... But this doesn't work, because the App\User factory isn't available yet.
So far, I have to do this:
$attributes = [
'name' => $faker->userName,
'password' => $faker->password,
];
$factory('App\User', $attributes);
$attributes['admin' => 1];
$factory('App\User', 'admin_user', $attributes);
Do you think this could this be improved ? I was thinking of a syntax like so:
$factory('extends:<class-or-shortname>', 'admin_user', [
'admin' => 1,
]);
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels