<?php
namespace App\Http\Resources\Pages\Blog;
use App\Helpers\ResourceHelper;
use App\Http\Resources\Pages\Contacts\CountryCollection;
use App\Http\Resources\Pages\Contacts\RegionCollection;
use App\Http\Resources\Pages\TermsConditions\BlockCollection;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
/**
* @OA\Schema(title="BlockResource",description="Block resource",
* @OA\Xml(name="BlockResource")
* )
*/
class SectionResource extends JsonResource
{
/**
* @OA\Property(property="text", type="string", example=""),
*/
public string|null $language;
public string|null $country;
public array|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);
$this->data = $resource['attributes'];
}
public function toArray(Request $request): array
{
return [
'text' => ResourceHelper::getValue($this->data['text'] ?? null, $this->country, $this->language),
'image' => ResourceHelper::getImage($this->data['image'] ?? null),
];
}
public static function collection($resource): SectionCollection
{
return new SectionCollection($resource);
}
}