'Laravel validation, dynamic date

Is it possible to have a dynamic date for a commitment date?

For example, we can hire a person 1 year in the future and commitment dates start in 2008 minimum

I have this for now? I don't like it

'date_commitment' => 'required|date|after:2008-12-31|before:2021-01-01'


Solution 1:[1]

concatenate the current year using the date function

'date_commitment' => 'required|date|after:2008-12-31|before:' . date('Y') + 2 . '-01-01'

would output 2021 now
would output 2023 two years from now

Solution 2:[2]

now you can user by jQuery : $('#end-date').datepicker( { dateFormat: 'yy-mm-dd',
maxDate:0,
beforeShow: function() { $(this).datepicker('option', 'minDate', $('#start-date').val()); $(this).datepicker('option', 'maxDate', $('#end-date').val());
if($('#start-date').val() === '') $(this).datepicker('option', 'maxDate', 0); } });

Solution 3:[3]

working here.

$end_date =date('Y-m-d',strtotime($request->input('start-date').'+ 240 day'));

$validator = Validator::make($request->all(),[                          
                        
            'start-date'    => 'required',               
                    
            'end-date'  => 'required|date|after:'.$request->input('start-date').'|before:'.$end_date.'',                
                        
            
        ]); 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Salim
Solution 2
Solution 3 Suraj Rao