62 lines
2.1 KiB
PHP
62 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Api\V2;
|
|
|
|
use App\Enums\Country;
|
|
use Illuminate\Validation\Rules\Password;
|
|
|
|
class UpdateCustomerRequest extends BaseApiRequest
|
|
{
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$fields = [
|
|
'firstname', 'lastname', 'email', 'password',
|
|
'birth_date', 'address', 'phone', 'country',
|
|
'city', 'postcode', 'opt_in'
|
|
];
|
|
//phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
$atLeast = function ($attribute, $value, $fail) use ($fields) {
|
|
if (!\in_array($attribute, $fields)) {
|
|
$fail(trans('require_at_least_field', [
|
|
'attributes' => rtrim(\implode(',', $fields), ',')
|
|
]));
|
|
}
|
|
};
|
|
return [
|
|
'firstname' => [$atLeast, 'string', 'min:2'],
|
|
'lastname' => [$atLeast, 'string', 'min:2'],
|
|
'email' => [$atLeast, 'email:rfc,dns,spoof,filter'],
|
|
'password' => [
|
|
$atLeast, Password::min(8)
|
|
->mixedCase()
|
|
->letters()
|
|
->numbers()
|
|
->symbols()
|
|
->uncompromised()
|
|
],
|
|
'birth_date' => [$atLeast, 'date_format:Y-m-d'],
|
|
'address' => [$atLeast, 'required_with:address2', 'string'],
|
|
'address2' => ['sometimes', 'string'],
|
|
'phone' => [$atLeast, 'string'],
|
|
'country' => [
|
|
$atLeast,
|
|
'numeric',
|
|
//phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function ($attribute, $value, $fail) {
|
|
if (!\in_array($value, Country::toValues())) {
|
|
$fail(trans('not_in'));
|
|
}
|
|
}
|
|
],
|
|
'city' => [$atLeast, 'string'],
|
|
'postcode' => [$atLeast, 'string'],
|
|
'opt_in' => [$atLeast, 'boolean'],
|
|
];
|
|
}
|
|
}
|