Mirich
Mirich

Reputation: 351

How to use datetimepicker in Laravel using laravelcollective

Good day to all I was creating a Laravel project and I was wondering how to put and use datetimepicker in the view if possible with laravelcollective if not please suggest something. I have used form::date but creates a simple textbox which is inappropriate. The code I ams using now:

{{Form::date('DateOfProduction', \Carbon\Carbon::now(), ['class'=>'form-control','style' => 'max-width: 200px'])}}

Upvotes: 1

Views: 12313

Answers (2)

Shalto
Shalto

Reputation: 88

Include this in your head

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
in your footer



<script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  </script>

and your input

{{ Form::text('date', '', array('id' => 'datepicker')) }}

Upvotes: 1

afikri
afikri

Reputation: 394

In your app blade template, you need to do is to include jquery and bootstrap datetimepicker before your javascript like

<script>
  $(function() {
    $( "#your_datepicker_id" ).datepicker({
    // dateFormat: 'dd/mm/yyyy',
    dateFormat: 'd/m/Y',
    changeMonth: true,
    changeYear: true});
    });
  </script>

then in your blade template that extending app, inside the form do as below

{!! Form::open(['route'=>'some-of-your-post-function', 'method'=>'POST', 'files'=>'true','class'=>'form']) !!}       

    <div class="form-group">
          {!! Form::label('Uploading Date') !!}
          {!! Form::text('date_of_upload',null, [
            'class' => 'form-control',
            'id' => 'your_datepicker_id',
          ]) !!}

      </div>
{!! Form::close() !!}

That's simple as that, hope that helps

Upvotes: 2

Related Questions