ldc-legaulois/app/Http/Requests/UpdateInfosRequest.php

59 lines
1.7 KiB
PHP
Raw Normal View History

<?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',
2021-03-21 22:51:19 +01:00
'year' => [
'required',
'numeric',
2021-05-04 09:27:59 +02:00
'gt:' . (date('Y') - 101), 'lt:' . (date('Y') - 12),
2021-03-21 22:51:19 +01:00
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
function ($attr, $value, $fail) {
$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'));
}
}
2021-03-21 22:51:19 +01:00
],
'address' => 'max:255',
'phone' => 'max:255',
'city' => 'required|string|max:255',
'postcode' => 'required'
];
}
}