- Make all tests pass Client (V4),CRMV2,CRMV4 - Simplify client submodule path - Move App_url to .env.testing
68 lines
2.6 KiB
PHP
68 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Api\V2;
|
|
|
|
use App\Enums\Country;
|
|
use Illuminate\Validation\Rules\Enum;
|
|
use Illuminate\Validation\Rules\Password;
|
|
|
|
/**
|
|
* @codeCoverageIgnore
|
|
*/
|
|
class UpdateCustomerRequest extends StoreCustomerRequest
|
|
{
|
|
/**
|
|
* 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'
|
|
];
|
|
$atLeast = function ($attribute) use ($fields) {
|
|
return 'required_without_all:' . collect($fields)
|
|
->filter(function ($fieldName) use ($attribute) {
|
|
return $fieldName !== $attribute;
|
|
})->implode(',');
|
|
};
|
|
return [
|
|
'firstname' => [$atLeast('firstname'), 'string', 'min:1', 'max:255'],
|
|
'lastname' => [$atLeast('lastname'), 'string', 'min:1', 'max:255'],
|
|
'email' => [$atLeast('email'), 'email:rfc,dns,spoof,filter', 'max:255'],
|
|
'password' => [
|
|
$atLeast('password'), 'max:255', Password::min(8)
|
|
->mixedCase()
|
|
->letters()
|
|
->numbers()
|
|
->symbols()
|
|
->uncompromised()
|
|
],
|
|
'birth_date' => [$atLeast('birth_date'), 'date_format:Y-m-d', 'max:255'],
|
|
'address' => [$atLeast('address'), 'required_with:address2', 'string', 'max:255'],
|
|
'address2' => ['sometimes', 'string', 'max:255'],
|
|
'phone' => [$atLeast('phone'), 'string', 'phone:' . (
|
|
($this->currentCountry && $this->currentCountry->get('iso')) ?
|
|
$this->currentCountry->get('iso') : implode(',', Country::getValidIsoAplha2Codes())
|
|
), 'max:255'],
|
|
'country' => [
|
|
$atLeast('country'),
|
|
'numeric',
|
|
new Enum(Country::class),
|
|
sprintf(
|
|
'in:%s',
|
|
implode(',', Country::getValidCountriesValues())
|
|
)
|
|
],
|
|
'city' => [$atLeast('city'), 'string', 'min:2', 'max:255'],
|
|
'postcode' => [$atLeast('postcode'), 'string', 'postal_code:' . (
|
|
($this->currentCountry && $this->currentCountry->get('iso')) ?
|
|
$this->currentCountry->get('iso') : implode(',', Country::getValidIsoAplha2Codes())
|
|
), 'max:255'],
|
|
'opt_in' => [$atLeast('opt_in'), 'boolean'],
|
|
];
|
|
}
|
|
}
|