38 lines
1.2 KiB
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class InvoiceLineResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'invoice_id' => $this->invoice_id,
'product_id' => $this->product_id,
'product_name' => $this->product ? $this->product->nom : null,
'packaging_id' => $this->packaging_id,
'packages_qty' => $this->packages_qty,
'units_qty' => $this->units_qty,
'description' => $this->description,
'qty_base' => $this->qty_base,
'unit_price' => $this->unit_price,
'unit_price_per_package' => $this->unit_price_per_package,
'tva_rate_id' => $this->tva_rate_id,
'discount_pct' => $this->discount_pct,
'total_ht' => $this->total_ht,
'product' => $this->whenLoaded('product'),
'packaging' => $this->whenLoaded('packaging'),
'tva_rate' => $this->whenLoaded('tvaRate'),
];
}
}