Error with date when upgrading to Laravel 7

Viewed 3254

I have successfully upgraded my Laravel instance to version 7. So far everything seems fine apart from the following error.

Argument 1 passed to Carbon\CarbonInterval::setLocalTranslator() must implement interface Symfony\Component\Translation\TranslatorInterface, instance of Carbon\Translator given, called in /var/www/laravel/vendor/nesbot/carbon/src/Carbon/Traits/Difference.php

I have followed the upgrade documentation and have added the following to my models (but still having the same problem).

protected function serializeDate(DateTimeInterface $date)
{
    return $date->format('Y-m-d H:i:s');
}
3 Answers

I have the same error here on the linux server but not under wampp...

it is being triggered by the following command : $hist->created_at->diffForHumans()

I have tried the new serialization as well in the model :

use DateTimeInterface;

/**
 * Prepare a date for array / JSON serialization.
 *
 * @param  \DateTimeInterface  $date
 * @return string
 */
protected function serializeDate(DateTimeInterface $date)
{
    return $date->format('Y-m-d H:i:s');
}

Found it... The migration is not going well it seems.

SO modify the composer.json to migrate to laravel 7 and symfony 5. Then remove vendor folder and reinstall everything

composer clearcache
composer install

then it worked again.

This worked for me on Laravel V7 Delete this file /vendor/symfony/translation/TranslatorInterface.php Then run this command to refresh the mapping: composer dump-autoload

Related