Yeah - just create it manually.
$factory->define(App\Thing::class, function ($faker) {
return [
'user_id' => factory('App\User')->create()->id,
'description' => $faker->paragraph
];
});
Summer Sale! All accounts are 50% off this week.
Just migrating from Laravel 4.2 to 5.1, and setting up the model factories. In the 4.2 version I uses to use the laracasts/testdummy package which offered similar functionality.
With testdummy to create dependent relationships you could use 'factory:class'.
Eg:
$factory('Class\Two', [
'relation_id' => 'factory:Class\One',
'name' => $faker->name
]);
Can something similar be done with Model Factories or does the relationship need to be created manually?
Eg:
$factory->define('App\Class\Two', function (Faker\Generator $faker) use ($factory) {
$relation = $factory->create('App\Class\One');
return [
'relation_id' => $relation->id,
'name' => $faker->name
];
});
Yeah - just create it manually.
$factory->define(App\Thing::class, function ($faker) {
return [
'user_id' => factory('App\User')->create()->id,
'description' => $faker->paragraph
];
});
Please or to participate in this conversation.