0
votes

I'd like to get month index from month name using Carbon.

But I use Turkish month names.

I pass a query string to index like this ?ay=Temmuz&yıl=2017 so carbon should give 7 in this case.

The relevant part in my index function is like this:

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

    / ... / 

}

When I click side bar and pass this query string it gives an error message like that:

"DateTime::__construct(): Failed to parse time string (Temmuz) at position 0 (T): The timezone could not be found in the database"

1
What is the server you are using?Nitish Kumar
I use vallet on 64 bit Ubuntu machine. Ubuntu 16.04 LTS with Laravel Framework 5.5.3Erdem

1 Answers

0
votes

on Linux

If you have trouble with translations, check locales installed in your system (local and production).

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.

And reboot your system. see documentation: http://carbon.nesbot.com/docs/#api-localization

For more you can refer to: Laravel Carbon localization not working (get localized name of month from number)

As the error you are getting is about Timezone not found in database.