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

50 lines
1.4 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-20 14:38:15 +01:00
'year' => ['required', 'numeric', 'gt:' . (date('Y') - 101), 'lt:' . (date('Y') + 1), 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'));
}
}],
'address' => 'max:255',
'phone' => 'max:255',
'city' => 'required|string|max:255',
'postcode' => 'required'
];
}
}