mirror of https://github.com/kcal-app/kcal.git
Fully remove Seeders and Facrtories (will re-add to deal with case change)
This commit is contained in:
parent
64cf3e274e
commit
5a732f9846
|
@ -1,95 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Database\Factories;
|
|
||||||
|
|
||||||
use App\Models\Food;
|
|
||||||
|
|
||||||
use Database\Support\Words;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
||||||
use Illuminate\Support\Arr;
|
|
||||||
|
|
||||||
class FoodFactory extends Factory
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $model = Food::class;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function definition(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'name' => Words::randomWords(Arr::random(['n', 'an'])),
|
|
||||||
'detail' => $this->faker->optional()->sentence(2),
|
|
||||||
'brand' => $this->faker->optional()->word,
|
|
||||||
'source' => $this->faker->optional()->url,
|
|
||||||
'notes' => $this->faker->optional(0.25)->paragraph,
|
|
||||||
'serving_size' => $this->faker->randomFloat(2, 1/2, 5),
|
|
||||||
'serving_unit' => $this->faker->randomElement(['tsp', 'tbsp', 'cup']),
|
|
||||||
'serving_weight' => $this->faker->numberBetween(5, 500),
|
|
||||||
'serving_unit_name' => $this->faker->optional(0.25)->word,
|
|
||||||
'calories' => $this->faker->randomFloat(2, 0, 100),
|
|
||||||
'fat' => $this->faker->randomFloat(2, 0, 10),
|
|
||||||
'cholesterol' => $this->faker->randomFloat(2, 0, 100),
|
|
||||||
'sodium' => $this->faker->randomFloat(2, 0, 500),
|
|
||||||
'carbohydrates' => $this->faker->randomFloat(2, 0, 20),
|
|
||||||
'protein' => $this->faker->randomFloat(2, 0, 20),
|
|
||||||
'tags' => $this->faker->words,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define a "tsp" serving unit.
|
|
||||||
*/
|
|
||||||
public function tspServingUnit()
|
|
||||||
{
|
|
||||||
return $this->state(function (array $attributes) {
|
|
||||||
return [
|
|
||||||
'serving_unit' => 'tsp',
|
|
||||||
'serving_size' => 1,
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define a "tbsp" serving unit.
|
|
||||||
*/
|
|
||||||
public function tbspServingUnit()
|
|
||||||
{
|
|
||||||
return $this->state(function (array $attributes) {
|
|
||||||
return [
|
|
||||||
'serving_unit' => 'tbsp',
|
|
||||||
'serving_size' => 1,
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define a "cup" serving unit.
|
|
||||||
*/
|
|
||||||
public function cupServingUnit()
|
|
||||||
{
|
|
||||||
return $this->state(function (array $attributes) {
|
|
||||||
return [
|
|
||||||
'serving_unit' => 'cup',
|
|
||||||
'serving_size' => 1,
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define no serving unit.
|
|
||||||
*/
|
|
||||||
public function noServingUnit()
|
|
||||||
{
|
|
||||||
return $this->state(function (array $attributes) {
|
|
||||||
return [
|
|
||||||
'serving_unit' => null,
|
|
||||||
'serving_unit_name' => 'head'
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Database\Factories;
|
|
||||||
|
|
||||||
use App\Models\Goal;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
||||||
|
|
||||||
class GoalFactory extends Factory
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $model = Goal::class;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function definition()
|
|
||||||
{
|
|
||||||
$from = $this->faker->dateTimeThisMonth;
|
|
||||||
$to = $this->faker->dateTimeBetween($from, '+1 year');
|
|
||||||
return [
|
|
||||||
'from' => $this->faker->randomElement([$from, null]),
|
|
||||||
'to' => $this->faker->randomElement([$to, null]),
|
|
||||||
'frequency' => $this->faker->randomElement(Goal::$frequencyOptions)['value'],
|
|
||||||
'name' => $this->faker->randomElement(Goal::getNameOptions())['value'],
|
|
||||||
'goal' => $this->faker->numberBetween(0, 2000),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Database\Factories;
|
|
||||||
|
|
||||||
use App\Models\Food;
|
|
||||||
use App\Models\IngredientAmount;
|
|
||||||
use App\Models\Recipe;
|
|
||||||
use App\Support\Nutrients;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class IngredientAmountFactory extends Factory
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $model = IngredientAmount::class;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function definition(): array
|
|
||||||
{
|
|
||||||
if ($this->faker->boolean(90)) {
|
|
||||||
$ingredient_factory = Food::factory();
|
|
||||||
$ingredient_type = Food::class;
|
|
||||||
$ingredient_unit = Nutrients::units()->pluck('value')->random(1)->first();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$ingredient_factory = Recipe::factory();
|
|
||||||
$ingredient_type = Recipe::class;
|
|
||||||
$ingredient_unit = 'serving';
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'ingredient_id' => $ingredient_factory,
|
|
||||||
'ingredient_type' => $ingredient_type,
|
|
||||||
'amount' => $this->faker->randomFloat(1, 1/3, 5),
|
|
||||||
'unit' => $ingredient_unit,
|
|
||||||
'detail' => $this->faker->optional(0.8)->realText(),
|
|
||||||
'weight' => $this->faker->numberBetween(0, 50),
|
|
||||||
'parent_id' => Recipe::factory(),
|
|
||||||
'parent_type' => Recipe::class,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define a specific parent.
|
|
||||||
*/
|
|
||||||
public function parent(Model $parent): static
|
|
||||||
{
|
|
||||||
return $this->state(function (array $attributes) use ($parent) {
|
|
||||||
return [
|
|
||||||
'parent_id' => $parent->id,
|
|
||||||
'parent_type' => $parent::class,
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define a specific ingredient.
|
|
||||||
*/
|
|
||||||
public function ingredient(Model $ingredient): static
|
|
||||||
{
|
|
||||||
return $this->state(function (array $attributes) use ($ingredient) {
|
|
||||||
return [
|
|
||||||
'ingredient_id' => $ingredient->id,
|
|
||||||
'ingredient_type' => $ingredient::class,
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Database\Factories;
|
|
||||||
|
|
||||||
use App\Models\JournalEntry;
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
||||||
|
|
||||||
class JournalEntryFactory extends Factory
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $model = JournalEntry::class;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function definition(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'user_id' => User::factory(),
|
|
||||||
'date' => $this->faker->dateTimeThisMonth,
|
|
||||||
'summary' => $this->faker->realText(50),
|
|
||||||
'calories' => $this->faker->randomFloat(2, 0, 500),
|
|
||||||
'fat' => $this->faker->randomFloat(2, 0, 50),
|
|
||||||
'cholesterol' => $this->faker->randomFloat(2, 0, 2000),
|
|
||||||
'sodium' => $this->faker->randomFloat(2, 0, 2000),
|
|
||||||
'carbohydrates' => $this->faker->randomFloat(2, 0, 100),
|
|
||||||
'protein' => $this->faker->randomFloat(2, 0, 100),
|
|
||||||
'meal' => $this->faker->randomElement(['breakfast', 'lunch', 'dinner', 'snacks']),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Database\Factories;
|
|
||||||
|
|
||||||
use App\Models\Recipe;
|
|
||||||
use Database\Support\Words;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
||||||
use Illuminate\Http\UploadedFile;
|
|
||||||
use Illuminate\Support\Arr;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
|
|
||||||
class RecipeFactory extends Factory
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $model = Recipe::class;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function definition(): array
|
|
||||||
{
|
|
||||||
$description = htmlspecialchars($this->faker->realText(500));
|
|
||||||
return [
|
|
||||||
'name' => Words::randomWords(Arr::random(['npan', 'npn', 'anpn'])),
|
|
||||||
'description' => "<p>{$description}</p>",
|
|
||||||
'description_delta' => '{"ops":[{"insert":"' . $description . '\n"}]}"',
|
|
||||||
'time_prep' => $this->faker->numberBetween(0, 20),
|
|
||||||
'time_cook' => $this->faker->numberBetween(0, 90),
|
|
||||||
'source' => $this->faker->optional()->url,
|
|
||||||
'servings' => $this->faker->numberBetween(1, 10),
|
|
||||||
'weight' => $this->faker->randomFloat(1, 60, 2000),
|
|
||||||
'tags' => $this->faker->words,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a recipe and add fake media to it.
|
|
||||||
*/
|
|
||||||
public function createOneWithMedia(array $attributes = []): Recipe {
|
|
||||||
Storage::fake('tests');
|
|
||||||
/** @var \App\Models\Recipe $recipe */
|
|
||||||
$recipe = $this->createOne($attributes);
|
|
||||||
$file = UploadedFile::fake()->image('recipe.jpg', 1600, 900);
|
|
||||||
$path = $file->store('tests');
|
|
||||||
$recipe->addMediaFromDisk($path)
|
|
||||||
->usingName($recipe->name)
|
|
||||||
->usingFileName("{$recipe->slug}.jpg")
|
|
||||||
->toMediaCollection();
|
|
||||||
return $recipe;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Database\Factories;
|
|
||||||
|
|
||||||
use App\Models\RecipeSeparator;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
||||||
|
|
||||||
class RecipeSeparatorFactory extends Factory
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $model = RecipeSeparator::class;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function definition()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'container' => 'ingredients',
|
|
||||||
'weight' => $this->faker->numberBetween(0, 100),
|
|
||||||
'text' => $this->faker->optional()->realText(20),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Database\Factories;
|
|
||||||
|
|
||||||
use App\Models\RecipeStep;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
||||||
|
|
||||||
class RecipeStepFactory extends Factory
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $model = RecipeStep::class;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function definition(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'number' => $this->faker->numberBetween(1, 50),
|
|
||||||
'step' => $this->faker->realText(500),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Database\Factories;
|
|
||||||
|
|
||||||
use App\Models\Tag;
|
|
||||||
use Database\Support\Words;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
||||||
|
|
||||||
class TagFactory extends Factory
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $model = Tag::class;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function definition(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'name' => Words::randomWords('a'),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Database\Factories;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class UserFactory extends Factory
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $model = User::class;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function definition(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'username' => $this->faker->unique()->userName,
|
|
||||||
'password' => Hash::make('password'),
|
|
||||||
'name' => $this->faker->name,
|
|
||||||
'remember_token' => Str::random(10),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Database\Seeders;
|
|
||||||
|
|
||||||
use Illuminate\Database\Seeder;
|
|
||||||
|
|
||||||
class DatabaseSeeder extends Seeder
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Seed the application's database.
|
|
||||||
*/
|
|
||||||
public function run(): void
|
|
||||||
{
|
|
||||||
$this->call(UserSeeder::class);
|
|
||||||
$this->call(FoodSeeder::class);
|
|
||||||
$this->call(RecipeSeeder::class);
|
|
||||||
$this->call(JournalEntrySeeder::class);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,162 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Database\Seeders;
|
|
||||||
|
|
||||||
use App\Models\Food;
|
|
||||||
use Illuminate\Database\Seeder;
|
|
||||||
|
|
||||||
class FoodSeeder extends Seeder
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the database seeds.
|
|
||||||
*/
|
|
||||||
public function run(): void
|
|
||||||
{
|
|
||||||
$default_foods = [
|
|
||||||
[
|
|
||||||
'name' => 'baking powder',
|
|
||||||
'serving_size' => 1,
|
|
||||||
'serving_unit' => 'tsp',
|
|
||||||
'serving_weight' => 4.6,
|
|
||||||
'calories' => 2.44,
|
|
||||||
'fat' => 0,
|
|
||||||
'cholesterol' => 0,
|
|
||||||
'sodium' => 0.488,
|
|
||||||
'carbohydrates' => 1.27,
|
|
||||||
'protein' => 0,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'egg',
|
|
||||||
'detail' => 'large',
|
|
||||||
'serving_size' => 1,
|
|
||||||
'serving_weight' => 50.3,
|
|
||||||
'calories' => 71.9,
|
|
||||||
'fat' => 5.01,
|
|
||||||
'cholesterol' => 0.207,
|
|
||||||
'sodium' => 0.0649,
|
|
||||||
'carbohydrates' => 0.483,
|
|
||||||
'protein' => 6.24,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'flour',
|
|
||||||
'detail' => 'all-purpose',
|
|
||||||
'serving_size' => 1,
|
|
||||||
'serving_unit' => 'cup',
|
|
||||||
'serving_weight' => 125,
|
|
||||||
'calories' => 455,
|
|
||||||
'fat' => 1.22,
|
|
||||||
'cholesterol' => 0,
|
|
||||||
'sodium' => 0.0025,
|
|
||||||
'carbohydrates' => 95.4,
|
|
||||||
'protein' => 12.9,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'milk',
|
|
||||||
'detail' => 'whole',
|
|
||||||
'serving_size' => 1,
|
|
||||||
'serving_unit' => 'cup',
|
|
||||||
'serving_weight' => 244,
|
|
||||||
'calories' => 146,
|
|
||||||
'fat' => 7.81,
|
|
||||||
'cholesterol' => 0.0293,
|
|
||||||
'sodium' => 0.0927,
|
|
||||||
'carbohydrates' => 11.4,
|
|
||||||
'protein' => 8,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'salt',
|
|
||||||
'detail' => 'table',
|
|
||||||
'serving_size' => 1,
|
|
||||||
'serving_unit' => 'tsp',
|
|
||||||
'serving_weight' => 6,
|
|
||||||
'calories' => 0,
|
|
||||||
'fat' => 0,
|
|
||||||
'cholesterol' => 0,
|
|
||||||
'sodium' => 2.33,
|
|
||||||
'carbohydrates' => 0,
|
|
||||||
'protein' => 0,
|
|
||||||
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'sugar',
|
|
||||||
'detail' => 'white',
|
|
||||||
'serving_size' => 1,
|
|
||||||
'serving_unit' => 'cup',
|
|
||||||
'serving_weight' => 200,
|
|
||||||
'calories' => 770,
|
|
||||||
'fat' => 0.64,
|
|
||||||
'cholesterol' => 0,
|
|
||||||
'sodium' => 0.002,
|
|
||||||
'carbohydrates' => 199,
|
|
||||||
'protein' => 0,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'vegetable oil',
|
|
||||||
'serving_size' => 1,
|
|
||||||
'serving_unit' => 'tbsp',
|
|
||||||
'serving_weight' => 14,
|
|
||||||
'calories' => 124,
|
|
||||||
'fat' => 14,
|
|
||||||
'cholesterol' => 0,
|
|
||||||
'sodium' => 0,
|
|
||||||
'carbohydrates' => 0,
|
|
||||||
'protein' => 0,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'peanut butter',
|
|
||||||
'detail' => 'organic creamy',
|
|
||||||
'brand' => 'Kirkland',
|
|
||||||
'serving_size' => 2,
|
|
||||||
'serving_unit' => 'tbsp',
|
|
||||||
'serving_weight' => 32,
|
|
||||||
'calories' => 180,
|
|
||||||
'fat' => 15,
|
|
||||||
'cholesterol' => 0,
|
|
||||||
'sodium' => 0.065,
|
|
||||||
'carbohydrates' => 7,
|
|
||||||
'protein' => 8,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'raisins',
|
|
||||||
'brand' => 'Kroger',
|
|
||||||
'serving_size' => 0.25,
|
|
||||||
'serving_unit' => 'cup',
|
|
||||||
'serving_weight' => 40,
|
|
||||||
'calories' => 140,
|
|
||||||
'fat' => 0,
|
|
||||||
'cholesterol' => 0,
|
|
||||||
'sodium' => 0.010,
|
|
||||||
'carbohydrates' => 33,
|
|
||||||
'protein' => 1,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'peanuts',
|
|
||||||
'detail' => 'dry roasted, unsalted',
|
|
||||||
'brand' => 'Kroger',
|
|
||||||
'serving_size' => 0.25,
|
|
||||||
'serving_unit' => 'cup',
|
|
||||||
'serving_weight' => 28,
|
|
||||||
'calories' => 160,
|
|
||||||
'fat' => 14,
|
|
||||||
'cholesterol' => 0,
|
|
||||||
'sodium' => 0,
|
|
||||||
'carbohydrates' => 6,
|
|
||||||
'protein' => 7,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'canned corn',
|
|
||||||
'detail' => 'golden sweet',
|
|
||||||
'brand' => 'WinCo',
|
|
||||||
'serving_size' => 0.5,
|
|
||||||
'serving_unit' => 'cup',
|
|
||||||
'serving_weight' => 125,
|
|
||||||
'calories' => 60,
|
|
||||||
'fat' => 0.5,
|
|
||||||
'sodium' => 0.2,
|
|
||||||
'carbohydrates' => 9,
|
|
||||||
'protein' => 1,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
Food::factory()->createMany($default_foods);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,128 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Database\Seeders;
|
|
||||||
|
|
||||||
use App\Models\Food;
|
|
||||||
use App\Models\JournalEntry;
|
|
||||||
use App\Models\Recipe;
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Database\Seeder;
|
|
||||||
use Illuminate\Support\Carbon;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
|
|
||||||
class JournalEntrySeeder extends Seeder
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the database seeds.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function run()
|
|
||||||
{
|
|
||||||
/** @var \App\Models\Food[] $foods */
|
|
||||||
foreach (['peanut butter', 'milk', 'egg', 'raisins'] as $name) {
|
|
||||||
$foods[$name] = Food::where('name', $name)->first();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var \App\Models\Recipe $recipe */
|
|
||||||
$recipe = Recipe::all()->first();
|
|
||||||
|
|
||||||
/** @var \App\Models\User $user */
|
|
||||||
$user = User::all()->first;
|
|
||||||
|
|
||||||
$default_entries = [
|
|
||||||
[
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'date' => Carbon::now()->toDateString(),
|
|
||||||
'summary' => '2 egg, 1 serving milk',
|
|
||||||
'calories' => $foods['egg']->calories * 2 + $foods['milk']->calories,
|
|
||||||
'fat' => $foods['egg']->fat * 2 + $foods['milk']->fat,
|
|
||||||
'cholesterol' => $foods['egg']->cholesterol * 2 + $foods['milk']->cholesterol,
|
|
||||||
'sodium' => $foods['egg']->sodium * 2 + $foods['milk']->sodium,
|
|
||||||
'carbohydrates' => $foods['egg']->carbohydrates * 2 + $foods['milk']->carbohydrates,
|
|
||||||
'protein' => $foods['egg']->protein * 2 + $foods['milk']->protein,
|
|
||||||
'meal' => 'breakfast',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'date' => Carbon::now()->toDateString(),
|
|
||||||
'summary' => '1 serving pancakes',
|
|
||||||
'calories' => $recipe->caloriesPerServing(),
|
|
||||||
'fat' => $recipe->fatPerServing(),
|
|
||||||
'cholesterol' => $recipe->cholesterolPerServing(),
|
|
||||||
'sodium' => $recipe->sodiumPerServing(),
|
|
||||||
'carbohydrates' => $recipe->carbohydratesPerServing(),
|
|
||||||
'protein' => $recipe->proteinPerServing(),
|
|
||||||
'meal' => 'lunch',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'date' => Carbon::now()->toDateString(),
|
|
||||||
'summary' => '1 serving pancakes',
|
|
||||||
'calories' => $recipe->caloriesPerServing(),
|
|
||||||
'fat' => $recipe->fatPerServing(),
|
|
||||||
'cholesterol' => $recipe->cholesterolPerServing(),
|
|
||||||
'sodium' => $recipe->sodiumPerServing(),
|
|
||||||
'carbohydrates' => $recipe->carbohydratesPerServing(),
|
|
||||||
'protein' => $recipe->proteinPerServing(),
|
|
||||||
'meal' => 'dinner',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'date' => Carbon::now()->toDateString(),
|
|
||||||
'summary' => '1 serving peanut butter',
|
|
||||||
'calories' => $foods['peanut butter']->calories,
|
|
||||||
'fat' => $foods['peanut butter']->fat,
|
|
||||||
'cholesterol' => $foods['peanut butter']->cholesterol,
|
|
||||||
'sodium' => $foods['peanut butter']->sodium,
|
|
||||||
'carbohydrates' => $foods['peanut butter']->carbohydrates,
|
|
||||||
'protein' => $foods['peanut butter']->protein,
|
|
||||||
'meal' => 'snacks',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'date' => Carbon::now()->toDateString(),
|
|
||||||
'summary' => '2 servings raisins',
|
|
||||||
'calories' => $foods['raisins']->calories * 2,
|
|
||||||
'fat' => $foods['raisins']->fat * 2,
|
|
||||||
'cholesterol' => $foods['raisins']->cholesterol * 2,
|
|
||||||
'sodium' => $foods['raisins']->sodium * 2,
|
|
||||||
'carbohydrates' => $foods['raisins']->carbohydrates * 2,
|
|
||||||
'protein' => $foods['raisins']->protein * 2,
|
|
||||||
'meal' => 'snacks',
|
|
||||||
],
|
|
||||||
];
|
|
||||||
JournalEntry::factory()->createMany($default_entries);
|
|
||||||
|
|
||||||
DB::table('journalables')->insert([
|
|
||||||
'journal_entry_id' => 1,
|
|
||||||
'journalable_id' => $foods['egg']->id,
|
|
||||||
'journalable_type' => Food::class,
|
|
||||||
]);
|
|
||||||
DB::table('journalables')->insert([
|
|
||||||
'journal_entry_id' => 1,
|
|
||||||
'journalable_id' => $foods['milk']->id,
|
|
||||||
'journalable_type' => Food::class,
|
|
||||||
]);
|
|
||||||
DB::table('journalables')->insert([
|
|
||||||
'journal_entry_id' => 2,
|
|
||||||
'journalable_id' => $recipe->id,
|
|
||||||
'journalable_type' => Recipe::class,
|
|
||||||
]);
|
|
||||||
DB::table('journalables')->insert([
|
|
||||||
'journal_entry_id' => 3,
|
|
||||||
'journalable_id' => $recipe->id,
|
|
||||||
'journalable_type' => Recipe::class,
|
|
||||||
]);
|
|
||||||
DB::table('journalables')->insert([
|
|
||||||
'journal_entry_id' => 4,
|
|
||||||
'journalable_id' => $foods['peanut butter']->id,
|
|
||||||
'journalable_type' => Food::class,
|
|
||||||
]);
|
|
||||||
DB::table('journalables')->insert([
|
|
||||||
'journal_entry_id' => 5,
|
|
||||||
'journalable_id' => $foods['raisins']->id,
|
|
||||||
'journalable_type' => Food::class,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,159 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Database\Seeders;
|
|
||||||
|
|
||||||
use App\Models\Food;
|
|
||||||
use App\Models\IngredientAmount;
|
|
||||||
use App\Models\Recipe;
|
|
||||||
use App\Models\RecipeStep;
|
|
||||||
use Illuminate\Database\Seeder;
|
|
||||||
|
|
||||||
class RecipeSeeder extends Seeder
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the database seeds.
|
|
||||||
*/
|
|
||||||
public function run(): void
|
|
||||||
{
|
|
||||||
/** @var \App\Models\Recipe $recipe */
|
|
||||||
$recipe = Recipe::factory()->create([
|
|
||||||
'name' => 'pancakes',
|
|
||||||
'description' => 'Basic pancakes in two steps.',
|
|
||||||
'servings' => 4,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$weight = 0;
|
|
||||||
$amounts = [
|
|
||||||
[
|
|
||||||
'ingredient_id' => Food::where('name', 'flour')
|
|
||||||
->first()->id,
|
|
||||||
'ingredient_type' => Food::class,
|
|
||||||
'amount' => 4.25,
|
|
||||||
'unit' => 'oz',
|
|
||||||
'parent_id' => $recipe->id,
|
|
||||||
'parent_type' => Recipe::class,
|
|
||||||
'weight' => $weight++,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'ingredient_id' => Food::where('name', 'sugar')
|
|
||||||
->first()->id,
|
|
||||||
'ingredient_type' => Food::class,
|
|
||||||
'amount' => 2,
|
|
||||||
'unit' => 'tbsp',
|
|
||||||
'parent_id' => $recipe->id,
|
|
||||||
'parent_type' => Recipe::class,
|
|
||||||
'weight' => $weight++,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'ingredient_id' => Food::where('name', 'baking powder')
|
|
||||||
->first()->id,
|
|
||||||
'ingredient_type' => Food::class,
|
|
||||||
'amount' => 2,
|
|
||||||
'unit' => 'tsp',
|
|
||||||
'parent_id' => $recipe->id,
|
|
||||||
'parent_type' => Recipe::class,
|
|
||||||
'weight' => $weight++,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'ingredient_id' => Food::where('name', 'salt')
|
|
||||||
->first()->id,
|
|
||||||
'ingredient_type' => Food::class,
|
|
||||||
'amount' => 1,
|
|
||||||
'unit' => 'tsp',
|
|
||||||
'parent_id' => $recipe->id,
|
|
||||||
'parent_type' => Recipe::class,
|
|
||||||
'weight' => $weight++,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'ingredient_id' => Food::where('name', 'egg')
|
|
||||||
->first()->id,
|
|
||||||
'ingredient_type' => Food::class,
|
|
||||||
'amount' => 1,
|
|
||||||
'parent_id' => $recipe->id,
|
|
||||||
'parent_type' => Recipe::class,
|
|
||||||
'weight' => $weight++,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'ingredient_id' => Food::where('name', 'milk')
|
|
||||||
->first()->id,
|
|
||||||
'ingredient_type' => Food::class,
|
|
||||||
'amount' => 1,
|
|
||||||
'unit' => 'cup',
|
|
||||||
'parent_id' => $recipe->id,
|
|
||||||
'parent_type' => Recipe::class,
|
|
||||||
'weight' => $weight++,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'ingredient_id' => Food::where('name', 'vegetable oil')
|
|
||||||
->first()->id,
|
|
||||||
'ingredient_type' => Food::class,
|
|
||||||
'amount' => 2,
|
|
||||||
'unit' => 'tbsp',
|
|
||||||
'parent_id' => $recipe->id,
|
|
||||||
'parent_type' => Recipe::class,
|
|
||||||
'weight' => $weight,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
IngredientAmount::factory()->createMany($amounts);
|
|
||||||
|
|
||||||
$steps = [
|
|
||||||
[
|
|
||||||
'recipe_id' => $recipe->id,
|
|
||||||
'number' => 1,
|
|
||||||
'step' => 'In a large bowl, mix flour, sugar, baking powder and salt. Make a well in the center, and pour in milk, egg and oil. Mix until smooth.',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'recipe_id' => $recipe->id,
|
|
||||||
'number' => 2,
|
|
||||||
'step' => 'Heat a lightly oiled griddle or frying pan over medium high heat. Pour or scoop the batter onto the griddle, using approximately 1/4 cup for each pancake. Brown on both sides and serve hot.',
|
|
||||||
]
|
|
||||||
];
|
|
||||||
RecipeStep::factory()->createMany($steps);
|
|
||||||
|
|
||||||
/** @var \App\Models\Recipe $recipe */
|
|
||||||
$recipe = Recipe::factory()->create([
|
|
||||||
'name' => 'peanut butter corn',
|
|
||||||
'description' => 'Peanut butter and corn -- YUM',
|
|
||||||
'servings' => 4,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$weight = 0;
|
|
||||||
$amounts = [
|
|
||||||
[
|
|
||||||
'ingredient_id' => Food::where('name', 'peanut butter')
|
|
||||||
->first()->id,
|
|
||||||
'ingredient_type' => Food::class,
|
|
||||||
'amount' => 2,
|
|
||||||
'unit' => 'cup',
|
|
||||||
'parent_id' => $recipe->id,
|
|
||||||
'parent_type' => Recipe::class,
|
|
||||||
'weight' => $weight++,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'ingredient_id' => Food::where('name', 'canned corn')
|
|
||||||
->first()->id,
|
|
||||||
'ingredient_type' => Food::class,
|
|
||||||
'amount' => 15.25,
|
|
||||||
'unit' => 'oz',
|
|
||||||
'parent_id' => $recipe->id,
|
|
||||||
'parent_type' => Recipe::class,
|
|
||||||
'weight' => $weight,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
IngredientAmount::factory()->createMany($amounts);
|
|
||||||
|
|
||||||
$steps = [
|
|
||||||
[
|
|
||||||
'recipe_id' => $recipe->id,
|
|
||||||
'number' => 1,
|
|
||||||
'step' => 'Mix it together.',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'recipe_id' => $recipe->id,
|
|
||||||
'number' => 2,
|
|
||||||
'step' => 'Eat it.',
|
|
||||||
]
|
|
||||||
];
|
|
||||||
RecipeStep::factory()->createMany($steps);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Database\Seeders;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Database\Seeder;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class UserSeeder extends Seeder
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the database seeds.
|
|
||||||
*/
|
|
||||||
public function run(): void
|
|
||||||
{
|
|
||||||
User::factory()->create([
|
|
||||||
'username' => 'admin',
|
|
||||||
'password' => Hash::make('admin'),
|
|
||||||
'name' => 'Admin',
|
|
||||||
'remember_token' => Str::random(10),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue