📜  Laravel 通过 13 岁验证生日 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:37.885000             🧑  作者: Mango

代码示例1
$dt = new Carbon\Carbon();
$before = $dt->subYears(13)->format('Y-m-d');

$rules = [
    ...
    'dob' => 'required|date|before:' . $before
];

---------------
  
Different Solution (Enhanced)

use Carbon\Carbon;

        $dt = new Carbon();
        $before18Years = $dt->subYears(18)->format('Y-m-d');


            'birthdate' => [
                'date_format:' . config('panel.date_format'),
                'required',
                'before:'.$before18Years,
            ],

file panel.php

 'Y-m-d',
    'time_format'         => 'H:i:s',
    'primary_language'    => 'en',
];