/home/bdqbpbxa/api-uniferx.goodface.com.ua/app/Http/Resources/Pages/Catalogs/FlyerResource.php
<?php
namespace App\Http\Resources\Pages\Catalogs;
use App\Helpers\ResourceHelper;
use App\Http\Resources\Pages\Cards\MissionCardCollection;
use App\Http\Resources\Pages\Contacts\CountryCollection;
use App\Http\Resources\Pages\Contacts\RegionCollection;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
/**
* @OA\Schema(title="FlyerResource",description="Flyer resource",
* @OA\Xml(name="FlyerResource")
* )
*/
class FlyerResource extends JsonResource
{
/**
* @OA\Property(property="title", type="string", example="title"),
* @OA\Property(property="file", type="string", example=""),
*/
public string|null $language;
public string|null $country;
public string|null $title;
public string|null $type;
public string|null $image;
public string|null $description;
public array|string|null $file;
public object|null $flyers;
// public array|object|null $data;
public function language($value): static
{
$this->language = $value;
return $this;
}
public function country($value): static
{
$this->country = $value;
return $this;
}
public function __construct($resource)
{
parent::__construct($resource);
// dd($resource);
$this->title = $resource->title;
$this->file = $resource->file;
// $this->data = $resource['attributes'];
}
public function toArray(Request $request): array
{
// dd(json_decode($this->data['title']));
return [
'title' => ResourceHelper::getValue($this->title ?? null, $this->country, $this->language),
'file' => ResourceHelper::getImage($this->file ?? null),
// 'flyers' => ResourceHelper::getValue(json_decode($this->data['flyers']) ?? null, $this->country, $this->language),
];
}
public static function collection($resource): FlyerCollection
{
return new FlyerCollection($resource);
}
}