belongsTo(PriceList::class); } public function scopeByPriceList($query, $id) { return $query->where($this->table . '.price_list_id', $id); } public function scopeByQuantity($query, $quantity) { return $query->orderBy('quantity', 'desc')->where($this->table . '.quantity', '<', $quantity)->first(); } }