Merge branch 'conditionnal-postal-code' into 'master'
fix: Added a condition to validate the postal code according to the country Closes ldc-web/projets/gen-game-web-instances/le-gaulois-tdf-2024#1 See merge request ldc-web/projets/gen-game-web!34
This commit is contained in:
commit
dcf2ad6079
1 changed files with 47 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ namespace App\Http\Requests\Fo\Customers;
|
|||
|
||||
use App\Rules\IsAdult;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
|
@ -50,7 +51,16 @@ class CreateAccountRequest extends FormRequest
|
|||
'phone' => 'nullable|max:255|phone:FR',
|
||||
'address' => 'required|string|min:1|max:255',
|
||||
'address2' => 'nullable|string|min:1|max:255',
|
||||
'postal_code' => 'required|string|min:1|postal_code:FR,BE,LU',
|
||||
'postal_code' => [
|
||||
'required',
|
||||
'string',
|
||||
'min:1',
|
||||
match ($this->integer('country')) {
|
||||
Country::belgium()->value => 'postal_code:BE',
|
||||
Country::luxembourg()->value => 'postal_code:LU',
|
||||
default => 'postal_code:FR',
|
||||
}
|
||||
],
|
||||
'city' => 'required|string|min:2|max:255',
|
||||
'birth_date' => ['required', new IsAdult(trans('Vous devez être majeur pour vous inscrire.'))],
|
||||
'country' => [
|
||||
|
|
@ -109,7 +119,7 @@ class CreateAccountRequest extends FormRequest
|
|||
*/
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
$messages = [
|
||||
'postal_code' => trans('validation.postal_code', [
|
||||
'countries' => \implode(', ', Country::getValidCountriesLabel()), 'examples' => 72000
|
||||
]),
|
||||
|
|
@ -119,5 +129,40 @@ class CreateAccountRequest extends FormRequest
|
|||
'email.unique' => trans('Un compte existe déjà avec cette adresse.'),
|
||||
'ok_cgv.accepted' => trans('Vous devez accepter les conditions d\'utilisation du site pour continuer.')
|
||||
];
|
||||
|
||||
$messages = match ($this->integer('country')) {
|
||||
Country::belgium()->value => array_merge(
|
||||
$messages,
|
||||
[
|
||||
'postal_code' => trans('validation.postal_code', [
|
||||
'countries' => Country::belgium()->label, 'examples' => 1000
|
||||
]),
|
||||
]
|
||||
),
|
||||
Country::luxembourg()->value => array_merge(
|
||||
$messages,
|
||||
[
|
||||
'postal_code' => trans('validation.postal_code', [
|
||||
'countries' => Country::luxembourg()->label, 'examples' => 1111
|
||||
]),
|
||||
]
|
||||
),
|
||||
default => array_merge(
|
||||
$messages,
|
||||
[
|
||||
'postal_code' => trans('validation.postal_code', [
|
||||
'countries' => \implode(', ', Arr::except(
|
||||
Country::getValidCountriesLabel(),
|
||||
[
|
||||
array_search(Country::belgium()->label, Country::getValidCountriesLabel()),
|
||||
array_search(Country::luxembourg()->label, Country::getValidCountriesLabel()),
|
||||
]
|
||||
)), 'examples' => 72000
|
||||
]),
|
||||
]
|
||||
),
|
||||
}; //end match
|
||||
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue