diff --git a/app/Models/Item.php b/app/Models/Item.php index 8b56cc5..4008b55 100644 --- a/app/Models/Item.php +++ b/app/Models/Item.php @@ -42,9 +42,9 @@ class Item extends Model return 'slug'; } - public function recipe() + public function recipes() { - return $this->belongsTo(Recipe::class, 'id'); + return $this->hasMany(Recipe::class); } public function getQuantityAttribute() diff --git a/tests/Feature/Models/ItemTest.php b/tests/Feature/Models/ItemTest.php index a58f441..dccee93 100644 --- a/tests/Feature/Models/ItemTest.php +++ b/tests/Feature/Models/ItemTest.php @@ -13,18 +13,24 @@ class ItemTest extends TestCase use RefreshDatabase; /** - * Test recipe relationship. + * Test recipes relationship. * * @return void */ - public function test_recipe_relationship() + public function test_recipes_relationship() { $item = Item::factory()->create(); + $recipe = Recipe::factory() ->for($item, 'craft') ->create(); - $this->assertEquals($recipe->id, $item->recipe->id); + $recipe2 = Recipe::factory() + ->for($item, 'craft') + ->create(); + + $this->assertEquals($recipe->id, $item->recipes[0]->id); + $this->assertEquals($recipe2->id, $item->recipes[1]->id); } /**