Laravel 4: Validate start and end date with before and after validation

后端 未结 5 1647
深忆病人
深忆病人 2021-01-27 07:22

I want to validate two date fields in a form which is from_date and end_date. Need to check from_date is less than end_date.

$rules = array(\'from_date\' => a         


        
5条回答
  •  悲&欢浪女
    2021-01-27 07:33

    Anyhow,

    I did as like this. So that even if any date in the form is empty that will auto fill and check the validation

    $inputs = Input::all();
    if(!empty($inputs))
    {
        $default_date_arr = array('from_date' => date('Y-m-d', strtotime('-1 days')), 'to_date' => date('Y-m-d'));
        $inputs = $inputs+$default_date_arr;
    }
    $rules = array('from_date' => array('sometimes','date_format:"Y-m-d"', 'before:'.$to_date) ,
                            'to_date' => array('sometimes','date_format:"Y-m-d"', 'after:'.$from_date ) );
    $validator = Validator::make($inputs,$rules);
    if($validator->fails())
    { ... }
    

    This may not be the answer for what i asked. But i needed just a way to finish this. May be will helpful for others.

提交回复
热议问题