1

Is there a way to set Laravel Collective date picker format to yyyy-mm-dd?

I am using now:

{{ Form::date('deadline', null,['class' => 'form-control']) }}

but in the front end I get an input field with mm/dd/yyyy inside. I tried parsing the Carbon instance as second parameter, but that does nothing.

{{ Form::date('deadline', \Carbon\Carbon::now()->format('Y-m-d'),['class' => 'form-control']) }}
Norgul
  • 4,613
  • 13
  • 61
  • 144

3 Answers3

6

You could pass an DateTime instance for the second parameter. As per the source code if the second parameter is an DateTime instance it would return the formatted date (Y-m-d).

So you could try this,

{{ Form::date('deadline', new \DateTime(), ['class' => 'form-control']) }}

Note:

As @Ajahi himalil stated in the comment, the value in the request would be different from the one selected. Please verify the data on form submission.

linktoahref
  • 7,812
  • 3
  • 29
  • 51
3

No, Laravel Collective does not provide this option.

Use https://eonasdan.github.io/bootstrap-datetimepicker/

{{ Form::text('deadline', null, ['class' => 'form-control', 'id'=>'datetimepicker']) }}

Javascript

$('#datetimepicker').datetimepicker({
    format: 'yyyy-mm-dd'
});
wbail
  • 536
  • 1
  • 7
  • 18
0

After applying all these methods and nothing working. simple input tag with date type is the only solution that i came to know instead of collective laravel.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Ajahi himalil
  • 190
  • 2
  • 9