Laravel 5: Wie überprüft datetime-input von 4 input-Feldern?

Ich habe ein Formular, das enthält eine Frist, und der Benutzer sollte die Frist in vier Eingabefelder wie dieses:

<div class="form-group col-lg-3">
    {!! Form::label('year', 'Year', ['class' => 'control-label']) !!}
    {!! Form::selectYear('year',$year, $year +1, null , ['class' => 'form-control']) !!}
</div>
<div class="form-group col-lg-3">
    {!! Form::label('month', 'Month', ['class' => 'control-label']) !!}
    {!! Form::selectRange('month', 1, 12 , null , ['class' => 'form-control']) !!}
</div>
<div class=" form-group col-lg-3">
    {!! Form::label('day', 'Day', ['class' => 'control-label']) !!}
    {!! Form::selectRange('day', 1, 31 , null , ['class' => 'form-control']) !!}
</div>
<div class=" form-group col-lg-3">
    {!! Form::label('hour', 'Hour', ['class' => 'control-label']) !!}
    {!! Form::selectRange('hour', 6, 23 , null , ['class' => 'form-control']) !!}
</div>

In einem formRequest, sammle ich diese vier Felder in einem Termin. Also meine formRequest ist wie folgt:

public function rules()
    {
        $this->prepInput();
        return [

        ];
    }
    public function prepInput(){
        $input=$this->all();
        ...
        $input['deadline']=$this->prepDeadline($input['hour'], $input['month'], $input['day'], $input['year']);
        ...
        $this->replace($input);
    }


    public function prepDeadline($hour,$month,$day, $year){

            $time = jDateTime::mktime($hour, 0, 0, $month, $day, $year);
            return $deadline = strftime("%Y-%m-%d %H:%M:%S", $time);        
    }

Ablauf der Frist ist eine Jalali datetime und ich brauche, um zu überprüfen, ob der Benutzer ausgewählt haben, ein gültiges Datum ist oder nicht (z.B. 1394/12/31 ist kein gültiges Datum ist). Die jDatetime Paket hat einen checkdate Methode, die funktioniert genau wie php checkdate. Wo und wie kann ich überprüfen das Datum in diesem formRequest und Benachrichtigen Sie den Benutzer, wählen Sie ein gültiges Datum?
In der Tat muss ich diese überprüfung stattfinden, bevor die Frist mit der übergabe an prepInput.

InformationsquelleAutor Ali Erfani | 2015-07-27

Schreibe einen Kommentar