app/Models/Item.php: add reagent_for relationship.
This commit is contained in:
parent
f9d44de6cb
commit
6f7c65fab3
2 changed files with 30 additions and 0 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Reference in a new issue