php - Run task before validation in Laravel -


OK, I have a form where the user asks for: -

  • The month in which they were born (January-December)
  • In the year in which they were born
  • / Li>

Then I agree with:

  $ rules = array ('???' = & gt; 'required: date'); $ Validator = verifier :: create ($ data, $ rule);  

But I do not know what I can do to put a date, month, year in a situation which I can put in my verification, even if Be on view or in process of verification.

Thank you, Tom

If you want to use the linked verification rule Your date is required to come in a format as a field, which will be able to identify Laravel's date parser (dd-mm-yyyy, dd / mm / yy, yyyy-mm-dd, etc.) Your form should really be in this case there is a single text field called 'date'.

If it comes in three separate fields, then you have to convert them to a field before coming to the accredited. Something like this might happen:

  $ rule = ['name' = & gt; ['Required'], 'email' = & gt; ['Required', 'Email'], 'Date' = & gt; ['required date'], ]; // Date of changing yyyy-mm-dd // TODO from three different areas: Make sure things can be null-padded? $ Date = input :: get ('year'). '-'. Input: ('month'). '-'. Input: get ('days'); $ V = VALITOR :: Creation (Input :: only ('name', 'email') + ['' date '' = & gt; $ date], $ rules);  

Comments