Files
opensem/app/Models/Shop/ArticlePrice.php
2020-08-20 01:10:38 +02:00

52 lines
1.3 KiB
PHP

<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Znck\Eloquent\Traits\BelongsToThrough;
class ArticlePrice extends Model
{
use BelongsToThrough;
protected $guarded = ['id'];
protected $table = 'shop_article_prices';
public function article_attribute()
{
return $this->belongsTo('App\Models\Shop\ArticleAttribute');
}
public function article()
{
return $this->belongsToThrough(
'App\Models\Shop\Article',
'App\Models\Shop\ArticleAttribute',
null,
'',
['App\Models\Shop\Article' => 'article_id', 'App\Models\Shop\ArticleAttribute' => 'article_attribute_id']
);
}
public function scopeByArticle($query, $id)
{
return $query->whereHas('article', function ($query) use ($id) {
$query->byArticle($id);
});
}
public function scopeByAttributeValue($query, $id)
{
return $query->whereHas('article_attribute', function ($query) use ($id) {
$query->byAttributeValue($id);
});
}
public function scopeByFamily($query, $id)
{
return $query->whereHas('article_attribute', function ($query) use ($id) {
$query->byFamily($id);
});
}
}