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

43 lines
907 B
PHP

<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class ArticleAttribute extends Model
{
protected $guarded = ['id'];
protected $table = 'shop_article_attributes';
public function article()
{
return $this->belongsTo('App\Models\Shop\Article');
}
public function attribute_value()
{
return $this->belongsTo('App\Models\Shop\ArticleAttributeValue', 'article_attribute_value_id');
}
public function prices()
{
return $this->hasMany('App\Models\Shop\ArticlePrice');
}
public function scopeByArticle($query, $id)
{
return $query->where('article_id', $id);
}
public function scopeByAttributeValue($query, $id)
{
return $query->where('attribute_value_id', $id);
}
public function scopeByFamily($query, $id)
{
return $query->whereHas('attribute_value', function ($query) use ($id) {
$query->byFamily($id);
});
}
}