[WIP] Add thumb on offers, refactor categories, try to fix counter on relations polymorphic with eage loader, bad pattern !
This commit is contained in:
@@ -23,9 +23,9 @@ class Offer extends Model
|
||||
return $this->article->categories();
|
||||
}
|
||||
|
||||
public function variation()
|
||||
public function tags()
|
||||
{
|
||||
return $this->belongsTo(Variation::class);
|
||||
return $this->article->tags();
|
||||
}
|
||||
|
||||
public function tariff()
|
||||
@@ -33,6 +33,11 @@ class Offer extends Model
|
||||
return $this->belongsTo(Tariff::class);
|
||||
}
|
||||
|
||||
public function variation()
|
||||
{
|
||||
return $this->belongsTo(Variation::class);
|
||||
}
|
||||
|
||||
public function scopeByArticle($query, $id)
|
||||
{
|
||||
return $query->where('article_id', $id);
|
||||
@@ -64,6 +69,20 @@ class Offer extends Model
|
||||
return $query->where('status_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByTag($query, $tag_id)
|
||||
{
|
||||
return $query->whereHas('article.tags', function ($query) use ($tag_id) {
|
||||
$query->where('tag_id', $tag_id);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeByTags($query, $tags)
|
||||
{
|
||||
return $query->whereHas('article.tags', function ($query) use ($tags) {
|
||||
$query->whereIn('tag_id', $tags);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeByVariation($query, $id)
|
||||
{
|
||||
return $query->where('variation_id', $id);
|
||||
|
||||
Reference in New Issue
Block a user