Add deep relations
This commit is contained in:
@@ -18,16 +18,6 @@ class Offer extends Model
|
||||
return $this->belongsTo(Article::class);
|
||||
}
|
||||
|
||||
public function categories()
|
||||
{
|
||||
return $this->article->categories();
|
||||
}
|
||||
|
||||
public function tags()
|
||||
{
|
||||
return $this->article->tags();
|
||||
}
|
||||
|
||||
public function tariff()
|
||||
{
|
||||
return $this->belongsTo(Tariff::class);
|
||||
@@ -38,14 +28,54 @@ class Offer extends Model
|
||||
return $this->belongsTo(Variation::class);
|
||||
}
|
||||
|
||||
public function price_lists()
|
||||
{
|
||||
return $this->hasManyThrough(PriceList::class, Tariff::class, 'id', 'tariff_id', 'id', 'id');
|
||||
}
|
||||
|
||||
public function categories()
|
||||
{
|
||||
return $this->article->categories();
|
||||
}
|
||||
|
||||
public function tags()
|
||||
{
|
||||
return $this->article->tags();
|
||||
}
|
||||
|
||||
public function get_price_lists()
|
||||
{
|
||||
return $this->tariff->price_lists();
|
||||
}
|
||||
|
||||
public function get_price_list_values()
|
||||
{
|
||||
return $this->tariff->price_lists->price_list_values();
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('status_id', 1);
|
||||
return $query->where($this->table . '.status_id', 1);
|
||||
}
|
||||
|
||||
public function scopeByArticle($query, $id)
|
||||
{
|
||||
return $query->where('article_id', $id);
|
||||
return $query->where($this->table . '.article_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByOffer($query, $id)
|
||||
{
|
||||
return $query->where($this->table . '.id', $id);
|
||||
}
|
||||
|
||||
public function scopeByStatus($query, $id)
|
||||
{
|
||||
return $query->where($this->table . '.status_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByVariation($query, $id)
|
||||
{
|
||||
return $query->where($this->table . '.variation_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByArticleNature($query, $article_nature_id)
|
||||
@@ -69,11 +99,6 @@ class Offer extends Model
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeByStatus($query, $id)
|
||||
{
|
||||
return $query->where('status_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByTag($query, $tag_id)
|
||||
{
|
||||
return $query->whereHas('article.tags', function ($query) use ($tag_id) {
|
||||
@@ -88,8 +113,4 @@ class Offer extends Model
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeByVariation($query, $id)
|
||||
{
|
||||
return $query->where('variation_id', $id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user