improve loading speed for container page

This commit is contained in:
omair saleh
2022-01-18 15:39:14 +08:00
parent 438f7fdff5
commit 5c374e2e19
4 changed files with 81 additions and 55 deletions
+7 -4
View File
@@ -5,6 +5,7 @@ namespace App\Http\Resources;
use App\Classes\ValueObjects\Constants\ContainerTypes;
use App\Models\Remark;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\DB;
class ContainerResource extends JsonResource
{
@@ -24,11 +25,13 @@ class ContainerResource extends JsonResource
'seal_reference' => $this->seal_reference,
'loading_date' => $this->loading_date ? $this->loading_date->format('d-m-Y') : $this->loading_date,
'transport' => new TransportResource($this->transports()->first()),
'packing_lists' => PackingListResource::collection($this->whenLoaded('packingLists', function(){
return $this->packingLists()->whereHas('packages')->get();
})),
'packages_count' => $this->packages->sum('quantity'),
'total_cbm' => $this->packages()->sum(DB::raw('(width/100) * (height/100) * (length/100) * quantity')),
'remarks' => RemarkResource::collection($this->remarks),
'status' => $this->status
'status' => $this->status,
'packing_lists' => $this->whenLoaded('packingLists', PackingListResource::collection($this->whenLoaded('packingLists', function(){
return $this->packingLists()->whereHas('packages')->get();
})))
];
}
}