Add factory for Space model and create space for every new user in UsersTableSeeder
MODIFY
database/factories/ModelFactory.php
database/factories/ModelFactory.php
use Faker\Generator;
use App\User;
+use App\Space;
use App\Earning;
use App\Spending;
@@ -15,6 +16,12 @@ $factory->define(User::class, function (Generator $faker) {
];
});
+$factory->define(Space::class, function (Generator $faker) {
+ return [
+ 'name' => $faker->firstName() . '\'s Space'
+ ];
+});
+
$factory->define(Earning::class, function (Generator $faker) {
return [
'happened_on' => $faker->dateTimeBetween('-50 days', 'now')->format('Y-m-d'),

MODIFY
database/seeds/UsersTableSeeder.php
database/seeds/UsersTableSeeder.php
use Illuminate\Database\Seeder;
use App\User;
+use App\Space;
class UsersTableSeeder extends Seeder {
public function run() {
- factory(User::class, 5)->create();
+ factory(User::class, 5)->create()->each(function ($user) {
+ $user->spaces()->attach(factory(Space::class)->create([
+ 'name' => $user->name . '\'s Space'
+ ]));
+ });
}
}

Add factory for Space model and create space for every new user in UsersTableSeeder