52 lines
1.7 KiB
PHP
52 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Resources\FormBuilder;
|
|
|
|
use App\Models\FormBuilder\FormFieldLibrary;
|
|
use App\Services\FormBuilder\FormFieldBindingService;
|
|
use App\Services\FormBuilder\FormFieldConfigService;
|
|
use App\Services\FormBuilder\FormFieldValidationRuleService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
/**
|
|
* @mixin FormFieldLibrary
|
|
*/
|
|
final class FormFieldLibraryResource extends JsonResource
|
|
{
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'organisation_id' => $this->organisation_id,
|
|
'name' => $this->name,
|
|
'slug' => $this->slug,
|
|
'field_type' => $this->field_type,
|
|
'label' => $this->label,
|
|
'help_text' => $this->help_text,
|
|
'options' => $this->options,
|
|
'validation_rules' => app(FormFieldValidationRuleService::class)->toJsonShape(
|
|
$this->resource->validationRules,
|
|
),
|
|
'configs' => app(FormFieldConfigService::class)->toJsonShape(
|
|
$this->resource->configs,
|
|
),
|
|
'default_is_required' => (bool) $this->default_is_required,
|
|
'default_is_filterable' => (bool) $this->default_is_filterable,
|
|
'default_binding' => app(FormFieldBindingService::class)->toJsonShape(
|
|
$this->resource->bindings->first(),
|
|
),
|
|
'translations' => $this->translations,
|
|
'description' => $this->description,
|
|
'usage_count' => (int) ($this->usage_count ?? 0),
|
|
'is_system' => (bool) $this->is_system,
|
|
'is_active' => (bool) $this->is_active,
|
|
];
|
|
}
|
|
}
|