diff --git a/app/Models/Recipe.php b/app/Models/Recipe.php index 30068da..4141d50 100644 --- a/app/Models/Recipe.php +++ b/app/Models/Recipe.php @@ -32,7 +32,8 @@ class Recipe extends Model protected $fillable = [ 'profession_id', 'category_id', - 'item_id' + 'item_id', + 'spell_id' ]; /** @@ -75,6 +76,14 @@ class Recipe extends Model return $this->belongsTo(RecipeCategory::class, 'category_id'); } + /** + * What spell this recipe peforms. + */ + public function spell() + { + return $this->belongsTo(Spell::class); + } + /** * What item this recipe crafts. */ diff --git a/database/factories/RecipeFactory.php b/database/factories/RecipeFactory.php index 00c5e7c..8b0fbb5 100644 --- a/database/factories/RecipeFactory.php +++ b/database/factories/RecipeFactory.php @@ -4,6 +4,7 @@ namespace Database\Factories; use App\Models\Profession; use App\Models\Item; +use App\Models\Spell; use App\Models\Recipe; use App\Models\RecipeCategory; @@ -30,6 +31,7 @@ class RecipeFactory extends Factory 'profession_id' => Profession::factory(), 'category_id' => RecipeCategory::factory(), 'item_id' => Item::factory(), + 'spell_id' => Spell::factory(), //'slug' => function (array $attributes) { // return Str::slug(Item::find($attributes['item_id'])->name); //} diff --git a/tests/Feature/Models/RecipeTest.php b/tests/Feature/Models/RecipeTest.php index 890f55b..adcf6ac 100644 --- a/tests/Feature/Models/RecipeTest.php +++ b/tests/Feature/Models/RecipeTest.php @@ -10,6 +10,7 @@ use App\Models\RecipeCategory; use App\Models\Profession; use App\Models\CharacterProfession; use App\Models\Character; +use App\Models\Spell; use App\Models\Item; class RecipeTest extends TestCase @@ -48,6 +49,22 @@ class RecipeTest extends TestCase $this->assertEquals($category->id, $recipe->category->id); } + /** + * Test spell relationship. + * + * @return void + */ + public function test_spell_relationship() + { + $spell = Spell::factory()->create(); + + $recipe = Recipe::factory() + ->for($spell) + ->create(); + + $this->assertEquals($spell->id, $recipe->spell->id); + } + /** * Test craft relationship. *