/home/bdqbpbxa/api-uniferx.goodface.com.ua/app/Http/Resources/Pages/Contacts/ContactsResource.php
<?php
namespace App\Http\Resources\Pages\Contacts;
use App\Helpers\ResourceHelper;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @OA\Schema(title="ContactsResource",description="Contacts resource",
* @OA\Xml(name="ContactsResource")
* )
*/
class ContactsResource extends JsonResource
{
/**
* @OA\Property(property="icon", type="string", example="https://uniferx-backend.test/storage/crops/trials/X2YZbZ7anmN5W3QdUn3iJEgacNxdXNKP1KTQakt8.txt"),
* @OA\Property(property="title", type="string", example="Phone"),
* @OA\Property(property="text", type="string", example="+49 173 762 7701"),
*/
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 [
'icon' => ResourceHelper::getImage($this->data['icon'] ?? null),
'title' => ResourceHelper::getValue($this->data['title'] ?? null, $this->country, $this->language),
'text' => ResourceHelper::getValue($this->data['text'] ?? null, $this->country, $this->language),
];
}
public static function collection($resource): ContactsCollection
{
return new ContactsCollection($resource);
}
}