Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Bradley James Ahrens's avatar

Bootstrap Date picker won't push the date into the database

Hi guys,

I'm using Bootstrap Datepicker* in one of my projects. It looks fine. It pops up and I can select a date and submit the form. Does anyone know where the problem could be?

*https://bootstrap-datepicker.readthedocs.io/en/latest/index.html

Here is my code:

create.blade.php

<div class="container">
  <div class="input-group date">
      <input type="text" class="form-control" id="datepicker" name="datepicker" value="{{ old('datepicker') }}" placeholder="MM/DD/YYYY">
  </div>
</div>

roomscontroller.php

public function store(Request $request)
    {
$room = Room::create([
'datepicker' => request()->datepicker
]);
}

createroomstable.php

public function up()
    {
        Schema::create('rooms', function (Blueprint $table) {
$table->string('datepicker')->nullable();
});
    }

Then, since create.blade.php is a section within the app.blade.php file...

app.blade.php

CSS files:

        <!-- Fonts -->
        <link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
        <!-- Bootstrap core CSS -->
        <link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
        <!-- Custom styles for sticky footer -->
        <link href="https://getbootstrap.com/docs/4.0/examples/sticky-footer/sticky-footer.css" rel="stylesheet">
        <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.standalone.min.css">

JS files:

    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
    <script src="{{ asset('js/app.js') }}"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.min.js"></script>
    <script>$(document).ready(function() {$('#datepicker').datepicker({startDate: "today()"});});</script>

I have made sure that:

  • the ID is the same
  • I refreshed the migration (several times)
  • the JS and CSS were in the right order

Possible solutions:

  • should the date be a string? I also tried with this instead: $table->date('datepicker')->nullable();

Other than that, I'm running out of ideas. Any help is appreciated. Thanks! :)

0 likes
4 replies
Snapey's avatar
Snapey
Best Answer
Level 122

It will be a string when it comes from the form, but it needs to be in the right format.

Is the date you are setting in the $dates array on the model?

If the column is in date/time format then sending the date as yyyy-mm-dd is the most robust

1 like
Bradley James Ahrens's avatar

@Snapey, you are a genius. absolute genius.

Thank you so much. I completely forgot about making the datepicker item fillable. Once I added it there, it all worked out.

Thanks again Snapey!!!

Cronix's avatar

You didn't show the form code, but I assume the datepicker input has a name="datepicker"?

Edit: nm, you got it working as I was typing lol. Glad you got it resolved. Strange it didn't throw an error?

1 like
Snapey's avatar

Well glad you solved it, but I didn't actually tell you to add it to $fillable. I suggested adding to the $dates array so that it is automatically parsed to a Carbon object.

Anyway, glad its resolved.

1 like

Please or to participate in this conversation.