<?php namespace App\Http\Resources; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class SubpedidoResource extends JsonResource { /** * Transform the resource into an array. * * @param Request $request * @return array */ public function toArray($request): array { $productos = $this->productos; foreach ($productos as $producto) { $producto['pivot']['total'] = number_format($producto->pivot->cantidad * $producto->precio, 2); } return [ 'id' => $this->id, 'nombre' => $this->nombre, 'productos' => $productos, 'aprobado' => (bool) $this->aprobado, 'total' => number_format($this->total(),2), 'total_transporte' => number_format($this->totalTransporte()), 'cantidad_transporte' => number_format($this->cantidadTransporte()), 'total_sin_devoluciones' => number_format($this->totalSinDevoluciones(),2), 'devoluciones_total' => number_format($this->devoluciones_total,2), 'devoluciones_notas' => $this->devoluciones_notas ]; } }