Archived
1
0
Fork 0

app/Models/Item.php: add reagent_for relationship.

This commit is contained in:
Henrik Hautakoski 2021-07-23 17:08:49 +02:00
parent f9d44de6cb
commit 6f7c65fab3
2 changed files with 30 additions and 0 deletions

View file

@ -47,6 +47,15 @@ class Item extends Model
return $this->hasMany(Recipe::class);
}
/**
* Get recipes that this item is reagent for.
*/
public function reagent_for()
{
return $this->belongsToMany(Recipe::class, 'reagents')
->withPivot('quantity');
}
public function getQuantityAttribute()
{
if ($this->pivot) {