Search code examples
laravel-8laravel-7laravel-migrations

Object of class Illuminate\Support\Facades\Date could not be converted to string


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());

Solution

  • 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());