问题
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');
}
回答1:
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');
}
回答2:
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.
来源:https://stackoverflow.com/questions/60621279/error-with-date-when-upgrading-to-laravel-7