From 78d5d8d50e0a4dfd98b4be073cb6226515af18e9 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Wed, 7 Jul 2021 16:18:01 +0200 Subject: [PATCH] Adding Spell Model --- app/Models/Spell.php | 39 +++++++++++++++++++++++++++++ database/factories/SpellFactory.php | 34 +++++++++++++++++++++++++ tests/Feature/Models/SpellTest.php | 29 +++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 app/Models/Spell.php create mode 100644 database/factories/SpellFactory.php create mode 100644 tests/Feature/Models/SpellTest.php diff --git a/app/Models/Spell.php b/app/Models/Spell.php new file mode 100644 index 0000000..f1bb5f5 --- /dev/null +++ b/app/Models/Spell.php @@ -0,0 +1,39 @@ +slug = Str::slug($spell->name); + }); + } + + public function recipe() + { + return $this->hasOne(Recipe::class); + } +} diff --git a/database/factories/SpellFactory.php b/database/factories/SpellFactory.php new file mode 100644 index 0000000..db635df --- /dev/null +++ b/database/factories/SpellFactory.php @@ -0,0 +1,34 @@ + $this->faker->unique()->randomNumber(5), + 'name' => $this->faker->unique()->sentence(8), + 'slug' => function (array $attributes) { + return Str::slug($attributes['name']); + } + ]; + } +} diff --git a/tests/Feature/Models/SpellTest.php b/tests/Feature/Models/SpellTest.php new file mode 100644 index 0000000..73c1111 --- /dev/null +++ b/tests/Feature/Models/SpellTest.php @@ -0,0 +1,29 @@ +create(); + $recipe = Recipe::factory() + ->for($spell) + ->create(); + + $this->assertEquals($recipe->name, $spell->recipe->name); + } +}