Skip to content

Commit d174593

Browse files
Merge pull request #225 from range-of-motion/71-split-model-factories
Split factories up into multiple files
2 parents 77546bf + 576ee27 commit d174593

File tree

11 files changed

+141
-92
lines changed

11 files changed

+141
-92
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
/** @var \Illuminate\Database\Eloquent\Factory $factory */
4+
5+
use App\Models\Budget;
6+
use Faker\Generator as Faker;
7+
8+
$factory->define(Budget::class, function (Faker $faker) {
9+
return [
10+
'period' => 'monthly',
11+
'amount' => $faker->randomNumber(3)
12+
];
13+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
/** @var \Illuminate\Database\Eloquent\Factory $factory */
4+
5+
use App\Models\ConversionRate;
6+
use Faker\Generator as Faker;
7+
8+
$factory->define(ConversionRate::class, function (Faker $faker) {
9+
return [
10+
'rate' => $faker->randomFloat(2, .5, 2)
11+
];
12+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
/** @var \Illuminate\Database\Eloquent\Factory $factory */
4+
5+
use App\Models\Currency;
6+
use Faker\Generator as Faker;
7+
8+
$factory->define(Currency::class, function (Faker $faker) {
9+
return [
10+
'name' => $faker->word(),
11+
'symbol' => $faker->word()
12+
];
13+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
/** @var \Illuminate\Database\Eloquent\Factory $factory */
4+
5+
use App\Models\Earning;
6+
use Faker\Generator as Faker;
7+
8+
$factory->define(Earning::class, function (Faker $faker) {
9+
return [
10+
'happened_on' => $faker->dateTimeBetween('-50 days', 'now')->format('Y-m-d'),
11+
'description' => implode(' ', array_map('ucfirst', $faker->words(3))),
12+
'amount' => $faker->randomNumber(3)
13+
];
14+
});

database/factories/ModelFactory.php

Lines changed: 0 additions & 92 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/** @var \Illuminate\Database\Eloquent\Factory $factory */
4+
5+
use App\Models\Recurring;
6+
use Faker\Generator as Faker;
7+
8+
$factory->define(Recurring::class, function (Faker $faker) {
9+
return [
10+
'type' => 'earning',
11+
'interval' => 'monthly',
12+
'day' => $faker->numberBetween(1, 28),
13+
'starts_on' => $faker->dateTimeBetween('-50 days', 'now')->format('Y-m-d'),
14+
'description' => implode(' ', array_map('ucfirst', $faker->words(3))),
15+
'amount' => $faker->randomNumber(3)
16+
];
17+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
/** @var \Illuminate\Database\Eloquent\Factory $factory */
4+
5+
use App\Models\Space;
6+
use Faker\Generator as Faker;
7+
8+
$factory->define(Space::class, function (Faker $faker) {
9+
return [
10+
'currency_id' => $faker->numberBetween(1, 3),
11+
'name' => $faker->firstName . '\'s Space'
12+
];
13+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/** @var \Illuminate\Database\Eloquent\Factory $factory */
4+
5+
use App\Models\Space;
6+
use App\Models\SpaceInvite;
7+
use App\Models\User;
8+
use Faker\Generator as Faker;
9+
10+
$factory->define(SpaceInvite::class, function (Faker $faker) {
11+
return [
12+
'space_id' => Space::all()->random()->id,
13+
'invitee_user_id' => User::all()->random()->id,
14+
'inviter_user_id' => User::all()->random()->id,
15+
'role' => 'regular'
16+
];
17+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
/** @var \Illuminate\Database\Eloquent\Factory $factory */
4+
5+
use App\Models\Spending;
6+
use Faker\Generator as Faker;
7+
8+
$factory->define(Spending::class, function (Faker $faker) {
9+
return [
10+
'happened_on' => $faker->dateTimeBetween('-50 days', 'now')->format('Y-m-d'),
11+
'description' => implode(' ', array_map('ucfirst', $faker->words(3))),
12+
'amount' => $faker->randomNumber(3)
13+
];
14+
});

database/factories/TagFactory.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
/** @var \Illuminate\Database\Eloquent\Factory $factory */
4+
5+
use App\Models\Tag;
6+
use Faker\Generator as Faker;
7+
8+
$factory->define(Tag::class, function (Faker $faker) {
9+
return [
10+
'name' => ucfirst($faker->word)
11+
];
12+
});

0 commit comments

Comments
 (0)