Add deep relations

This commit is contained in:
Ludovic CANDELLIER
2022-01-14 00:03:21 +01:00
parent 95ca3c6404
commit 050fd76122
13 changed files with 159 additions and 30 deletions

View File

@@ -20,6 +20,11 @@ class PriceList extends Model
return $this->belongsTo(Tariff::class);
}
public function offers()
{
return $this->hasManyThrough(Offer::class, Tariff::class, 'id', 'tariff_id', 'id', 'id');
}
public function sale_channel()
{
return $this->belongsTo(SaleChannel::class);
@@ -44,4 +49,11 @@ class PriceList extends Model
{
return $query->where($this->table . '.status_id', $id);
}
public function scopeByOffer($query, $id)
{
return $query->whereHas('offers', function ($query) use ($id) {
$query->byOffer($id);
});
}
}