验证开始日期时间和结束日期时间

时间:2018-05-30 08:06:16

标签: laravel laravel-5.3 laravel-validation

我想在函数中验证两列: 1)entry_dateTime 2)close_dateTime

  

close_datetime将超过entry_dateTime。我该如何进行验证?

例如,entry_dateTime 1/1/2018 09:15:14,那么close_dateTime必须大于entry_dateTime,2/1/201 08:00:00

我的功能:



public function store(Request $request)
    {
      $input = $request->all();

        $tradeID= Auth::user()->trade()->create($input);

        $reasons=$request->input('reason');

                        //Loop for creating KEY as Value
                        $data = [];
                        foreach($reasons as $key => $value) {

                            $data[] = ['reason_id' => $value];

                        };         
       
 if($data > 0) {

            foreach ($data as $datum) {
                $tradeID->tradereason()->save (new TradeReason($datum));
            }

        }




1 个答案:

答案 0 :(得分:1)

您可以使用之后验证规则来说明结束时间应该在输入时间之后:

public function store(Request $request)
{
    $rules = [
        'entry_dateTime' => ['required', 'date'],
        'close_dateTime' => ['required', 'date', 'after:entry_dateTime'],
    ];

    $this->validate($request, $rules);

    $input = $request->all();

    ...
}