Drop UsersTableSeeder and use DatabaseSeeder to generate a user and space for testing with tags, earnings and spendings
MODIFY
database/seeds/DatabaseSeeder.php
database/seeds/DatabaseSeeder.php
@@ -4,6 +4,75 @@ use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder {
public function run() {
- $this->call(UsersTableSeeder::class);
+ $year = date('Y');
+
+ // User
+ $user = \App\User::create([
+ 'name' => 'Daan',
+ 'email' => 'daniel@pixely.me',
+ 'password' => '$2y$12$eQ4s9CL8xg7Y6PoGNY4xuehr.d2u0e0VJ5CywkwqtQoyy/ntoP.pO' // hoi
+ ]);
+
+ // Space
+ $space = \App\Space::create([
+ 'currency_id' => 1,
+ 'name' => 'Daan\'s Space'
+ ]);
+
+ $user->spaces()->attach($space);
+
+ // Tags
+ $tagBills = \App\Tag::create(['space_id' => $space->id, 'name' => 'Bills']);
+ $tagFood = \App\Tag::create(['space_id' => $space->id, 'name' => 'Food']);
+ $tagTransport = \App\Tag::create(['space_id' => $space->id, 'name' => 'Transport']);
+
+ for ($i = 1; $i < 12; $i ++) {
+ // Income
+ \App\Earning::create([
+ 'space_id' => $space->id,
+ 'happened_on' => $year . '-' . $i . '-24',
+ 'description' => 'Wage',
+ 'amount' => 25000
+ ]);
+
+ // Bills
+ \App\Spending::create([
+ 'space_id' => $space->id,
+ 'tag_id' => $tagBills->id,
+ 'happened_on' => $year . '-' . $i . '-01',
+ 'description' => 'Phone Subscription',
+ 'amount' => 2500
+ ]);
+
+ \App\Spending::create([
+ 'space_id' => $space->id,
+ 'tag_id' => $tagBills->id,
+ 'happened_on' => $year . '-' . $i . '-01',
+ 'description' => 'Car Insurance',
+ 'amount' => 4500
+ ]);
+
+ // Food
+ for ($j = 0; $j < rand(1, 10); $j ++) {
+ \App\Spending::create([
+ 'space_id' => $space->id,
+ 'tag_id' => $tagFood->id,
+ 'happened_on' => $year . '-' . $i . '-' . rand(1, 28),
+ 'description' => '-',
+ 'amount' => 250 * rand(1, 5)
+ ]);
+ }
+
+ // Transport
+ for ($j = 0; $j < rand(1, 3); $j ++) {
+ \App\Spending::create([
+ 'space_id' => $space->id,
+ 'tag_id' => $tagTransport->id,
+ 'happened_on' => $year . '-' . $i . '-' . rand(1, 28),
+ 'description' => '-',
+ 'amount' => 1000 * rand(1, 5)
+ ]);
+ }
+ }
}
}

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

Drop UsersTableSeeder and use DatabaseSeeder to generate a user and space for testing with tags, earnings and spendings