Updated the address attribute in multiple requests and views to use the new 'postal_address' translation key for consistency.
95 lines
3.1 KiB
PHP
95 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Fo\Customer;
|
|
|
|
use App\Actions\Crm\UpdateCustomerInput;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Date;
|
|
use Infrastructure\Adapters\Services\AppCustomerAuthService;
|
|
|
|
class UpdateInfosRequest extends FormRequest
|
|
{
|
|
public function __construct(
|
|
private readonly AppCustomerAuthService $authService
|
|
) {
|
|
}
|
|
|
|
public function authorize(): bool
|
|
{
|
|
return $this->authService->check();
|
|
}
|
|
|
|
#[\Override]
|
|
protected function prepareForValidation()
|
|
{
|
|
$this->merge([
|
|
'opt_in' => $this->boolean('opt_in'),
|
|
]);
|
|
}
|
|
|
|
public function toUpdateCustomerInput(): UpdateCustomerInput
|
|
{
|
|
return new UpdateCustomerInput(
|
|
firstname: $this->string('firstname')->value(),
|
|
lastname: $this->string('lastname')->value(),
|
|
birthDate: $this->string('birth_date')->value(),
|
|
phone: ! $this->string('phone')->isEmpty() ?
|
|
$this->string('phone')->value() : null,
|
|
city: $this->string('city')->value(),
|
|
postcode: $this->string('postcode')->value(),
|
|
address: ! $this->string('address')->isEmpty() ?
|
|
$this->string('address')->value() : null,
|
|
optIn: $this->boolean('opt_in'),
|
|
);
|
|
}
|
|
|
|
/** @return array<string,mixed> */
|
|
public function rules(): array
|
|
{
|
|
$majorityDate = Date::now()->subYears(18)->format('Y-m-d');
|
|
|
|
return [
|
|
'firstname' => ['required', 'string', 'max:255'],
|
|
'lastname' => ['required', 'string', 'max:255'],
|
|
'birth_date' => [
|
|
'required',
|
|
'date',
|
|
'date_format:Y-m-d',
|
|
'before_or_equal:' . $majorityDate,
|
|
],
|
|
'address' => ['nullable', 'string', 'max:255'],
|
|
'phone' => ['nullable', 'phone:FR'],
|
|
'city' => ['required', 'string', 'max:255'],
|
|
'postcode' => ['required', 'postal_code:FR'],
|
|
'opt_in' => ['boolean'],
|
|
];
|
|
}
|
|
|
|
/** @return array<string,string> */
|
|
#[\Override]
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'birth_date.before_or_equal' => trans('validation.custom.birth_date.before_or_equal'),
|
|
'birth_date.date' => trans('validation.custom.birth_date.date'),
|
|
'birth_date.date_format' => trans('validation.custom.birth_date.date_format'),
|
|
];
|
|
}
|
|
|
|
/** @return array<string,string> */
|
|
#[\Override]
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'firstname' => trans('validation.attributes.first_name'),
|
|
'lastname' => trans('validation.attributes.last_name'),
|
|
'birth_date' => trans('validation.attributes.date_of_birth'),
|
|
'address' => trans('validation.custom.attributes.postal_address'),
|
|
'phone' => trans('validation.attributes.phone'),
|
|
'city' => trans('validation.attributes.city'),
|
|
'postcode' => trans('validation.attributes.postal_code'),
|
|
];
|
|
}
|
|
}
|