ServiceCategory
has many Service
public function services(): HasMany {
return $this->hasMany(Service::class, 'category_id');
}
Service
has many Price
public function prices(): HasMany {
return $this->hasMany(ServicePrice::class, 'service_id');
}
Let's say prices
table has a price_value
column, how do I get the lowest and highest price?
I used this method but every time the query returns a list of ServiceCategory
instead of a list of Price
.
What I tried:
ServiceCategory::with('services.prices')->get();
// Or Even
ServiceCategory::first()->with('services.prices')->get();
And:
ServiceCategory::has('services')->with('services:category_id')->with(['services.prices' => function ($q) {
$q->select('price');
}])->get();
Still no chance to only return a collection of Price