0

I am having this error after upgrading my project from laravel 7 to laravel 8 could someone explain it to me coz the project;s migrations were working well but now I can not run artisan migrate

     $table->date('booked_from')->default(new Date());
        $table->date('booked_to')->default(new Date());
The Only Smart Boy
  • 578
  • 19
  • 39
  • The error msg seems pretty clear? `default()` expects a string, presumably something like `2021-05-29 01:02:03` or whatever, but `new Date()` is an Illuminate\Support\Facades\Date object. If you just want to give it today's date, you could simply use `date('Y-m-d')` or some other format? – Don't Panic May 29 '21 at 12:03
  • I wanted to pick the current date when an insertion is made just like mysql's current timestamp works – The Only Smart Boy May 29 '21 at 12:07

1 Answers1

0

An alternative to one of the many solutions provide in the question Don't Panic provides in his comment above, you can also leverage the Carbon DateTime package which comes with Laravel.

$table->date('booked_from'->default(Carbon::now());
$table->date('booked_to')->default(Carbon::now());
Peppermintology
  • 9,343
  • 3
  • 27
  • 51