Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Laravel validating birthdate by 13 years old

$dt = new CarbonCarbon();
$before = $dt->subYears(13)->format('Y-m-d');

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

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

use CarbonCarbon;

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


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

file panel.php

<?php

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

Comment

PREVIOUS NEXT
Code Example
Php :: laravel migration remove unique 
Php :: php check version ubuntu 
Php :: disable quantity field in woocommerce 
Php :: case inside laravel query 
Php :: laravel RuntimeException Session store not set on request. 
Php :: php loop through list 
Php :: how validate data if is exist must not be empty in laravel 
Php :: test curl php 
Php :: Could not find package laravel/ with stability stable. 
Php :: [DoctrineDBALDBALException]Unknown database type enum requested, DoctrineDBALPlatformsMySqlPlatform may not support it. 
Php :: fetch body show in php code 
Php :: how to add script in WordPress admin page 
Php :: php echo an array to console 
Php :: php session time out default 
Php :: php slugify 
Php :: test if php is installed 
Php :: max_execution_time php 
Php :: wordpress truncate text 
Php :: php read csv file into array 
Php :: woocommerce check if user is logged in 
Php :: laravel routing controller get and post method 
Php :: logout in php 
Php :: php enter line break 
Php :: convert multi-dimensional array into a single array in laravel 
Php :: laravel old value not working in textarea 
Php :: laravel query by relationship 
Php :: convert query result to array php 
Php :: php capitalize first letter 
Php :: How to get a WordPress post by slug 
Php :: get last letter in php 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =