update logic
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Service\Order;
|
||||
|
||||
use App\Enums\Invoice\InvoiceStatus;
|
||||
use App\Enums\Order\OrderStatus;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OrderDetailResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'order_num' => $this->order_num,
|
||||
'status' => $this->status,
|
||||
'status_text' => OrderStatus::from((int) $this->status)->label(),
|
||||
'total' => (float) $this->total,
|
||||
'created_at' => $this->created_at?->toISOString(),
|
||||
'customer' => $this->whenLoaded('customer', fn () => [
|
||||
'id' => $this->customer->id,
|
||||
'name' => $this->customer->fullname,
|
||||
'email' => $this->customer->email,
|
||||
]),
|
||||
'invoice' => $this->whenLoaded('invoice', fn () => [
|
||||
'id' => $this->invoice->id,
|
||||
'invoice_number' => $this->invoice->invoice_number,
|
||||
'status' => $this->invoice->status,
|
||||
'status_text' => InvoiceStatus::tryFrom((int) $this->invoice->status)?->label() ?? '-',
|
||||
'sub_total' => (float) $this->invoice->sub_total,
|
||||
'tax' => (float) $this->invoice->tax,
|
||||
'total' => (float) $this->invoice->total,
|
||||
'due_date' => $this->invoice->due_date?->toISOString(),
|
||||
'paid_at' => $this->invoice->paid_at?->toISOString(),
|
||||
]),
|
||||
'items' => $this->whenLoaded('orderItems') ? OrderItemResource::collection($this->orderItems) : [],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user