Files
opensem/app/Models/Shop/PriceListValue.php
Ludovic CANDELLIER 050fd76122 Add deep relations
2022-01-14 00:03:21 +01:00

47 lines
1.1 KiB
PHP

<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Wildside\Userstamps\Userstamps;
use Znck\Eloquent\Traits\BelongsToThrough;
class PriceListValue extends Model
{
use BelongsToThrough, SoftDeletes, Userstamps;
protected $guarded = ['id'];
protected $table = 'shop_price_list_values';
public function price_list()
{
return $this->belongsTo(PriceList::class);
}
public function tariff()
{
return $this->belongsToThrough(
'App\Models\Shop\Tariff',
'App\Models\Shop\PriceList',
null,
'',
[
'App\Models\Shop\Tariff' => 'tariff_id',
'App\Models\Shop\PriceList' => 'price_list_id'
]
);
}
public function scopeByPriceList($query, $id)
{
return $query->where($this->table . '.price_list_id', $id);
}
public function scopeByQuantity($query, $quantity)
{
return $query->orderBy('quantity', 'desc')->where($this->table . '.quantity', '<', $quantity)->first();
}
}