58 lines
2.1 KiB
PHP
58 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class HardwareResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'name' => $this->name,
|
|
'type' => $this->type,
|
|
'brand' => $this->brand,
|
|
'model' => $this->model,
|
|
'serial_number' => $this->serial_number,
|
|
'status' => $this->status,
|
|
|
|
// Format brut pour les inputs date HTML (YYYY-MM-DD)
|
|
'purchase_date' => $this->purchase_date?->format('Y-m-d'),
|
|
'commissioning_date' => $this->commissioning_date?->format('Y-m-d'),
|
|
'warranty_expiration_date' => $this->warranty_expiration_date?->format('Y-m-d'),
|
|
|
|
// Format français pour l'affichage (DD/MM/YYYY)
|
|
'purchase_date_formatted' => $this->purchase_date?->format('d/m/Y') ?? 'Non spécifiée',
|
|
'commissioning_date_formatted' => $this->commissioning_date?->format('d/m/Y') ?? 'Non spécifiée',
|
|
'warranty_expiration_date_formatted' => $this->warranty_expiration_date?->format('d/m/Y') ?? 'Non spécifiée',
|
|
|
|
'location' => $this->location,
|
|
'ip_address' => $this->ip_address,
|
|
'order_id' => $this->order_id,
|
|
|
|
// Relation éventuelle avec la commande
|
|
'order' => $this->relationLoaded('order') && $this->order ? [
|
|
'id' => $this->order->id,
|
|
'number' => $this->order->number,
|
|
'label' => $this->order->label,
|
|
] : null,
|
|
|
|
'notes' => $this->notes,
|
|
|
|
// Propriétés calculées
|
|
'is_under_warranty' => $this->is_under_warranty,
|
|
'warranty_status_label' => $this->warranty_status_label,
|
|
'warranty_remaining_days' => $this->warranty_remaining_days,
|
|
|
|
'created_at' => $this->created_at?->format('d/m/Y H:i'),
|
|
];
|
|
}
|
|
}
|