Search code examples
laraveldatephp-carbon

how to translate day in laravel use carbon


I'm editing a script to customize the day into Indonesian, how do I translate it in carbon getdays?

this is the script contained in app/Support/Date.php

 public static function dayFromInt($num)
{
    return Arr::get(Carbon::getDays(), $num);

}

Solution

  • Well, I couldn't make Carbon::getDates() work with different locale, but it just returns an array of the days of the week, so you can change the function like:

    public static function dayFromInt($num)
    {
        //change with values in your language
        $weekdays = [
            'Sunday',
            'Monday',
            'Tuesday',
            'Wednesday',
            'Thursday',
            'Friday',
            'Saturday'
        ];
        return Arr::get($weekdays, $num);
    }