Error with date when upgrading to Laravel 7

守給你的承諾、 提交于 2020-05-15 05:08:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!