Add deep relations
This commit is contained in:
@@ -15,6 +15,11 @@ class Tariff extends Model
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_tariffs';
|
||||
|
||||
public function offers()
|
||||
{
|
||||
return $this->hasMany(Offer::class);
|
||||
}
|
||||
|
||||
public function sale_channel()
|
||||
{
|
||||
@@ -37,6 +42,11 @@ class Tariff extends Model
|
||||
return $this->hasMany(PriceList::class);
|
||||
}
|
||||
|
||||
public function price_list_values()
|
||||
{
|
||||
return $this->hasManyThrough(PriceListValue::class, PriceList::class);
|
||||
}
|
||||
|
||||
public function scopeByAutocomplete($query, $str)
|
||||
{
|
||||
return $query->where($this->table . '.name', 'LIKE', "%${str}%")
|
||||
@@ -53,4 +63,11 @@ class Tariff extends Model
|
||||
{
|
||||
return $query->where($this->table . '.status_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByOffer($query, $id)
|
||||
{
|
||||
return $query->whereHas('offers', function ($query) use ($id) {
|
||||
$query->where('id', $id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user