create feature sa create list claim and price to work per dealer
This commit is contained in:
@@ -54,4 +54,52 @@ class Work extends Model
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all dealer prices for this work
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function dealerPrices()
|
||||
{
|
||||
return $this->hasMany(WorkDealerPrice::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get price for specific dealer
|
||||
*
|
||||
* @param int $dealerId
|
||||
* @return WorkDealerPrice|null
|
||||
*/
|
||||
public function getPriceForDealer($dealerId)
|
||||
{
|
||||
return $this->dealerPrices()
|
||||
->where('dealer_id', $dealerId)
|
||||
->active()
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get price for specific dealer (including soft deleted)
|
||||
*
|
||||
* @param int $dealerId
|
||||
* @return WorkDealerPrice|null
|
||||
*/
|
||||
public function getPriceForDealerWithTrashed($dealerId)
|
||||
{
|
||||
return $this->dealerPrices()
|
||||
->withTrashed()
|
||||
->where('dealer_id', $dealerId)
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all active prices for this work
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function activeDealerPrices()
|
||||
{
|
||||
return $this->hasMany(WorkDealerPrice::class)->active();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user