Localized Dates In Laravel and Carbon

By adding one single line of code to any of your service providers in Laravel, your $user->created_at->diffForHumans() will be localized.

Code to add: Carbon::setLocale(app()->getLocale());


<?php namespace App\Providers;

use Carbon\Carbon;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider {

    public function register() {
        // ...


        // ...

It sets the locale according to your application locale.

Show Comments