Files
opensem/app/Models/Shop/Offer.php

91 lines
2.1 KiB
PHP

<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use App\Traits\Model\HasComments;
class Offer extends Model
{
use HasComments;
protected $guarded = ['id'];
protected $table = 'shop_offers';
public function article()
{
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);
}
public function variation()
{
return $this->belongsTo(Variation::class);
}
public function scopeByArticle($query, $id)
{
return $query->where('article_id', $id);
}
public function scopeByArticleNature($query, $article_nature_id)
{
return $query->whereHas('article.article_nature', function ($query) use ($article_nature_id) {
$query->byArticleNature($article_nature_id);
});
}
public function scopeByCategory($query, $category_id)
{
return $query->whereHas('article.categories', function ($query) use ($category_id) {
$query->where('category_id', $category_id);
});
}
public function scopeByPackage($query, $package_id)
{
return $query->whereHas('variation', function ($query) use ($package_id) {
$query->byPackage($package_id);
});
}
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) {
$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);
}
}