pedi2/app/Http/Resources/ProductoResource.php

33 lines
983 B
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductoResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'nombre' => $this->nombre,
'precio' => $this->precio,
'categoria' => $this->categoria,
'proveedor' => optional($this->proveedor)->nombre,
'economia_solidaria' => optional($this->proveedor)->economia_solidaria,
'nacional' => optional($this->proveedor)->nacional,
'imagen' => optional($this->poster)->url(),
'descripcion' => $this->descripcion,
'apto_veganxs' => $this->apto_veganxs,
'apto_celiacxs' => $this->apto_celiacxs,
'requiere_notas' => $this->requiere_notas,
];
}
}