belongsTo(ArticleNature::class); } public function invoiceItems() { return $this->hasMany(InvoiceItem::class); } public function offers() { return $this->hasMany(Offer::class); } public function prices() { return $this->hasManyDeep( PriceListValue::class, [Offer::class, Tariff::class, PriceList::class], ['article_id', 'id', 'tariff_id'], ['id', 'tariff_id', 'id'], ); } public function product() { return $this->morphTo(); } public function siblings() { return $this->hasMany(Article::class, 'name', 'name'); } public function tags() { return $this->morphToMany(Tag::class, 'taggable'); } public function tariffs() { return $this->hasManyThrough(Tariff::class, Offer::class, 'article_id', 'id', 'id', 'tariff_id'); // return $this->belongsToMany(Tariff::class, Offer::$table, 'id', 'id', 'tariff_id', 'tariff_id'); } public function scopeByArticle($query, $id) { return $query->where($this->table . '.id', $id); } public function scopeByAutocomplete($query, $str) { return $query->where($this->table . '.name', 'LIKE', "%${str}%"); } public function scopeByArticleNature($query, $id) { return $query->where($this->table . '.article_nature_id', $id); } public function scopeByCategory($query, $category_id) { return $category_id ? $query->whereHas('categories', function ($query) use ($category_id) { $query->where('id', $category_id); }) : $query; } public function scopeByProduct($query, $model) { return $query->where($this->table . '.product_type', $model); } public function scopeByProductId($query, $model_id) { return $query->where($this->table . '.product_id', $model_id); } public function scopeByTag($query, $tag_id) { return $tag_id ? $query->whereHas('tags', function ($query) use ($tag_id) { $query->where('id', $tag_id); }) : $query; } public function scopeByTags($query, $tags) { return $tags ? $query->whereHas('tags', function ($query) use ($tags) { $query->whereIn('id', $tags); }) : $query; } public function scopeWithOffers($query) { return $query->has('offers'); } public function scopeWithAvailableOffers($query, $sale_channel_id = false) { return $query->whereHas('offers', function ($query) use ($sale_channel_id) { $query->active()->bySaleChannel($sale_channel_id); }); } public function scopeVisible($query) { return $query->where($this->table . '.visible', 1); } }