Correct alternative that implements a validator for a date field in Laravel

1

a.

$this->validate($request, [
    'data_nascimento' => 'regex:ddmmyyyy',
]);

b.

$this->validate($request, [
    'data_nascimento' => 'required|date',
]);

c.

$this->validate($request, [
    'data_nascimento' => 'digits:8|integer',
]);

d.

$this->validate($request, [
    'data_nascimento' => 'datetime|null',
]);

I'm between A and B, I need help.

    
asked by anonymous 01.11.2017 / 00:38

1 answer

1

I believe this is the best, its date coming from the screen is in the Brazilian format, ie day , month and year >, use date_format in the format d / m / Y :

$this->validate($request, [
    'data_nascimento' => 'required|date_format:"d/m/Y"',
]);

Reference : date_format: format

    
01.11.2017 / 00:42