From 50ece979332145a791c391a06b03483433185da5 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Sun, 16 Aug 2026 15:13:34 +0700 Subject: [PATCH] feat: add getForEdit method to RestockService for enhanced restock item retrieval and media handling --- app/Services/Admin/Manage/RestockService.php | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/Services/Admin/Manage/RestockService.php b/app/Services/Admin/Manage/RestockService.php index 665b775..5b38690 100644 --- a/app/Services/Admin/Manage/RestockService.php +++ b/app/Services/Admin/Manage/RestockService.php @@ -61,6 +61,31 @@ public function paginated(int $perPage = 25, string $search = '', string $sort = return $paginator; } + public function getForEdit(Restock $restock): array + { + $restock->load([ + 'restockItems' => fn ($q) => $q + ->select(['id', 'restock_id', 'product_variant_id', 'quantity', 'unit_price', 'subtotal']), + 'restockItems.productVariant:id,name', + ]); + + $media = $restock->getFirstMedia('photos'); + + return [ + 'id' => $restock->id, + 'stock_type' => $restock->stock_type->value, + 'notes' => $restock->notes, + 'photo_key' => $media?->getCustomProperty('s3_key') ?? $media?->file_name, + 'photo_url' => $media ? $this->s3Service->getTemporaryUrl($media->getPath()) : null, + 'items' => $restock->restockItems->map(fn ($item) => [ + 'id' => $item->id, + 'product_variant_id' => $item->product_variant_id, + 'quantity' => $item->quantity, + 'unit_price' => $item->unit_price, + ]), + ]; + } + public function getItems(Restock $restock): \Illuminate\Support\Collection { return $restock->restockItems()