invert query from offers->articles to articles->offers
This commit is contained in:
@@ -86,6 +86,13 @@ class Article extends Model implements HasMedia
|
||||
|
||||
public function scopeWithOffers($query)
|
||||
{
|
||||
return $query->has('Offers');
|
||||
return $query->has('offers');
|
||||
}
|
||||
|
||||
public function scopeWithCurrentOffers($query)
|
||||
{
|
||||
return $query->whereHas('offers', function ($query) {
|
||||
$query->where('status_id', 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,11 @@ use Spatie\Translatable\HasTranslations;
|
||||
use Rinvex\Tags\Traits\Taggable;
|
||||
use Wildside\Userstamps\Userstamps;
|
||||
|
||||
use Kalnoy\Nestedset\NodeTrait;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
use HasTranslations, InteractsWithMedia, SoftDeletes, Taggable, Userstamps;
|
||||
use HasTranslations, InteractsWithMedia, NodeTrait, SoftDeletes, Taggable, Userstamps;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'categories';
|
||||
@@ -41,4 +43,9 @@ class Category extends Model
|
||||
{
|
||||
return $query->where('category_id', $category_id);
|
||||
}
|
||||
|
||||
public function scopeVisible($query)
|
||||
{
|
||||
return $query->where('visible', 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,11 @@ class Offer extends Model
|
||||
return $this->belongsTo(Variation::class);
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('status_id', 1);
|
||||
}
|
||||
|
||||
public function scopeByArticle($query, $id)
|
||||
{
|
||||
return $query->where('article_id', $id);
|
||||
|
||||
Reference in New Issue
Block a user