Files
opensem/app/Models/Shop/ArticlePrice.php
2021-10-04 14:09:51 +02:00

35 lines
754 B
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 price()
{
return $this->hasOne(Price::class);
}
public function article_family()
{
return $this->belongsTo(ArticleNature::class);
}
public function scopeByQuantity($query, $quantity)
{
return $query->orderBy('quantity', 'desc')->where('quantity', '<', $quantity)->first();
}
public function scopeByFamily($query, $id)
{
return $query->where($this->table . '.article_family_value_id', $id);
}
}