class Coffee extends Model
{
public function bags()
{
return $this->belongsToMany(Bag::class)->withPivot('price');
}
public function getLowestPrice()
{
return $this->bags()->min('price');
}
}
If you want to follow conventions you could change getLowestPrice to getLowestPriceAttribute