belongsTo(PriceList::class); } public function tariff() { return $this->belongsToThrough(Tariff::class, PriceList::class, null, '', [ 'App\Models\Shop\Tariff' => 'tariff_id', 'App\Models\Shop\PriceList' => 'price_list_id', ] ); } public function vat() { return $this->belongsTo(Tax::class, 'tax_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(); } public function scopeBySaleChannel($query, $sale_channel_id) { return $query->with([ 'price_list' => function ($query) use ($sale_channel_id) { return $query->bySaleChannel($sale_channel_id); }, ]); } }