ldc-boutique-cnc-sable/app/Http/Requests/Bo/Pages/UpdatePageRequest.php

59 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Requests\Bo\Pages;
use App\Actions\Pages\UpdatePageInput;
use App\Models\Page;
use Domain\Models\ValueObjects\SeoMetadata;
use Illuminate\Foundation\Http\FormRequest;
use Infrastructure\Adapters\Services\AppAdminAuthService;
class UpdatePageRequest extends FormRequest
{
public function __construct(
private readonly AppAdminAuthService $authService
) {
}
public function authorize(): bool
{
return $this->authService->check();
}
public function toUpdatePageInput(Page $page): UpdatePageInput
{
return new UpdatePageInput(
page: $page,
seo: new SeoMetadata(
title: $this->string('seo_title')->value(),
description: $this->string('seo_description')->value(),
),
title: $this->filled('title') ? $this->string('title')->value() : null,
content: $this->string('content')->value(),
);
}
/** @return array<string,mixed> */
public function rules(): array
{
return [
'seo_title' => ['required', 'string', 'between:45,70'],
'seo_description' => ['required', 'string', 'between:50,160'],
'title' => ['nullable', 'string', 'min:3', 'max:255'],
'content' => ['required', 'string'],
];
}
#[\Override]
public function attributes(): array
{
return [
'seo_title' => trans('validation.custom.attributes.seo_title'),
'seo_description' => trans('validation.custom.attributes.seo_description'),
'title' => trans('validation.attributes.title'),
'content' => trans('validation.attributes.content'),
];
}
}