I am working with a form that is being used in both the create and edit views. I have a date field and I want to set the default value depending on the view it is being used in. In the case of the create view I want to have the default set to today, and in the edit view I want to display the value stored in the database. Here is my code:
{!! Form::date('calibration_due_date', isset($tool->calibration_due_date)?$tool->calibration_due_date->format('Y-m-d'): Carbon\Carbon::now()->toDateString(), array('class' => 'form-control', 'required')) !!}
The problem is on the create view, it is not displaying todays date as expected, it is actually displaying a date from one of several items stored in the database...very randomly, it's not the first record, or the last, but record number 7. I have dumped the $tool
variable and have confirmed that it is not set (I get an error confirming this) and when I change the code to this:
{!! Form::date('calibration_due_date', Carbon\Carbon::now()->toDateString(), array('class' => 'form-control', 'required')) !!}
I get today's date as expected. As you can see I am using the Carbon plugin as well as the HTML collective.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire