ldc-boutique-cnc-sable/app/Http/Requests/CustomerRegisterRequest.php
2021-03-25 17:59:02 +01:00

56 lines
1.9 KiB
PHP

<?php
namespace App\Http\Requests;
use Carbon\Carbon;
use Illuminate\Foundation\Http\FormRequest;
class CustomerRegisterRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'email' => 'required|email:rfc,dns,spoof|max:255',
'username' => 'required|string|max:255|unique:customers,username',
'firstname' => 'required|string|max:255',
'lastname' => 'required|string|max:255',
'day' => 'required|alpha_num|gt:0|lt:32',
'month' => 'required|alpha_num|gt:0|lt:13',
'year' => [
'required', 'alpha_num', 'gt:' . (date('Y') - 101), 'lt:' . (date('Y') + 1),
function ($attribute, $value, $fail) {
$birthDate = Carbon::createFromDate($this->year, $this->month, $this->day);
// @phpcs:ignore PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace
if (
$birthDate->format('dmY') !== $this->day . $this->month . $this->year ||
$birthDate > Carbon::now()
) {
$fail(__('Veuillez entrer une date de naissance valide'));
}
}
],
'address' => 'sometimes|max:255',
'phone' => 'sometimes|max:255',
'city' => 'required|string|max:255',
'postcode' => 'required',
'password' => 'required|confirmed|min:8|max:255',
'password' => 'required|confirmed|min:8|max:255',
'optin' => 'sometimes',
];
}
}