碳从月份名称获取月份索引

时间:2017-09-20 18:13:00

标签: php laravel laravel-5 php-carbon

我想使用Carbon获得月份名称的月份索引。

但我使用土耳其月份名称。

我将查询字符串传递给像?ay=Temmuz&yıl=2017这样的索引,所以在这种情况下碳应该给出7。

我的索引功能中的相关部分是这样的:

public function index()
{
    $gonderiler = Gonderi::latest();

    if ($ay = request('ay'))
    {
        Carbon::setLocale(config('app.locale'));
        $gonderiler->whereMonth('created_at', Carbon::parse($ay)->month);
    }

    if ($yil = request('yil'))
    {
        $gonderiler->whereYear('created_at', $yil);
    }

    / ... / 

}

当我单击侧栏并传递此查询字符串时,它会显示如下错误消息:

  

“DateTime :: __ construct():无法解析时间字符串(Temmuz)   位置0(T):在数据库“

中找不到时区

1 个答案:

答案 0 :(得分:0)

Linux上的

如果您在翻译时遇到问题,请检查系统中安装的区域设置(本地和生产)。

locale -a to list locales enabled.
sudo locale-gen tr_TR.UTF-8 to install a new locale.
sudo dpkg-reconfigure locales to publish all locale enabled.

重新启动系统。请参阅文档:http://carbon.nesbot.com/docs/#api-localization

有关详情,请参阅:Laravel Carbon localization not working (get localized name of month from number)

由于您收到的错误是在数据库中找不到Timezone

相关问题