ldc-boutique-cnc/app/Http/Resources/ShopResource.php

50 lines
1 KiB
PHP
Raw Normal View History

2022-12-19 16:20:00 +01:00
<?php
namespace App\Http\Resources;
2023-03-01 11:02:42 +01:00
use App\Models\Shop\Shop;
2022-12-19 16:20:00 +01:00
use Illuminate\Http\Resources\Json\JsonResource;
class ShopResource extends JsonResource
{
2023-03-01 11:02:42 +01:00
/** @var \App\Models\Shop\Shop */
2022-12-19 16:20:00 +01:00
private $shop;
/** @var array */
private $skeleton = [
'id' => 0,
'name' => '',
'address' => '',
'postal_code' => 0,
'city' => '',
'phone' => '',
'gmaps_embed_href' => 0,
];
/**
* ShopResource
*
2023-03-01 11:02:42 +01:00
* @param \App\Models\Shop\Shop $shop
2022-12-19 16:20:00 +01:00
*/
public function __construct(Shop $shop)
{
$this->shop = $shop;
}
/**
* Transform the resource into an array.
*
* @param mixed $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
*/
public function toArray($request)
{
// phpcs:enable
return array_intersect_key(
$this->shop->toArray(),
$this->skeleton
);
}
}