62 lines
1.9 KiB
PHP
62 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class UpdateInfosRequest extends FormRequest
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
}
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return Auth::guard('customer')->check();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'firstname' => 'required|string|max:255',
|
|
'lastname' => 'required|string|max:255',
|
|
'day' => 'required|numeric|gt:0|lt:32',
|
|
'month' => 'required|numeric|gt:0|lt:13',
|
|
'year' => [
|
|
'required',
|
|
'numeric',
|
|
'gt:' . (date('Y') - 101), 'lt:' . (date('Y') +1),
|
|
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function ($attr, $value, $fail) {
|
|
$MJ = Carbon::now()->subYears(18);
|
|
$dateTest = Carbon::createFromDate($this->year, $this->month, $this->day);
|
|
if (
|
|
$dateTest->format('dmY') !== $this->day . $this->month . $this->year ||
|
|
$dateTest->getTimestamp() > time()
|
|
) {
|
|
$fail(__('Veuillez entrer une date de naissance valide'));
|
|
}
|
|
if (!$dateTest->lessThanOrEqualTo($MJ)) {
|
|
$fail(__("Vous devez être majeur pour vous inscrire."));
|
|
}
|
|
}
|
|
],
|
|
'address' => 'max:255',
|
|
'phone' => 'max:255',
|
|
'city' => 'required|string|max:255',
|
|
'postcode' => 'required'
|
|
];
|
|
}
|
|
}
|