Laravel: Convert Input Text Into Date To Validate With "after"

- 1 answer

I'm using Bootstrap 3 Datetimepicker to get a datetime from a form:

{!! Form::text('somedate', null, array('class' => 'datetimepicker', 'id' => 'somedate')) !!}

Datetimepicker plugin expects a text input type to works. If I change it to a date input type, the plugin do not work.

So, on my controller, I'm doing some validations:

$validator = Validator::make($request->all(), [                 
  'somedate' => 'required|after:tomorrow',

This is not working because "after" validation expects a date input type. How can I convert my text field to a date on my controller before it gets validate?



Try adding the date rule to those rules before the after rule.

'somedate' => 'required|date|after:tomorrow'

You can also use the date_format rule instead of date if you need to use a specific format.

Laravel 5.2 - Validation - Rule After