feat: Add active pricing details to service list resource and eager load only active pricings in the service repository.
This commit is contained in:
@@ -32,6 +32,12 @@ class ServiceListResource extends JsonResource
|
|||||||
'stock' => $this->stock,
|
'stock' => $this->stock,
|
||||||
'price' => $this->price,
|
'price' => $this->price,
|
||||||
'price_sale' => $this->price_sale,
|
'price_sale' => $this->price_sale,
|
||||||
|
'pricing' => $this->pricings->mapWithKeys(function ($pricing) {
|
||||||
|
return [$pricing->billing_cycle => $pricing->price];
|
||||||
|
}),
|
||||||
|
'pricing_sale' => $this->pricings->mapWithKeys(function ($pricing) {
|
||||||
|
return [$pricing->billing_cycle => $pricing->price_sale];
|
||||||
|
}),
|
||||||
'group' => $this->category->name,
|
'group' => $this->category->name,
|
||||||
'os' => $this->osVersions->groupBy('os_group_id')->map(function ($versions) {
|
'os' => $this->osVersions->groupBy('os_group_id')->map(function ($versions) {
|
||||||
$group = $versions->first()->osGroup;
|
$group = $versions->first()->osGroup;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class ServiceRepository extends BaseApiRepository implements ServiceRepositoryIn
|
|||||||
public function getActiveServices(int $limit = 10)
|
public function getActiveServices(int $limit = 10)
|
||||||
{
|
{
|
||||||
return $this->model
|
return $this->model
|
||||||
->with(['osVersions.osGroup', 'category'])
|
->with(['osVersions.osGroup', 'category', 'pricings' => fn($q) => $q->where('is_active', 1)])
|
||||||
->where('is_active', 1)
|
->where('is_active', 1)
|
||||||
->orderBy('sort_order', 'asc')
|
->orderBy('sort_order', 'asc')
|
||||||
->paginate($limit);
|
->paginate($limit);
|
||||||
|
|||||||
Reference in New Issue
Block a user