How use carbon in Laravel 5.2 application-wide

Add the following line to the aliases array in the config/app.php:

'Carbon' => 'Carbon\Carbon'

And you need to add use Carbon; every class where you want to use it.


You can declare some fields in your models using the following structure:

protected $dates = ['created_at', 'updated_at', 'disabled_at','mydate'];

All of those fields will automatically be Carbon instances and you will be able to use them in your views like:

{{ $article->mydate->diffForHumans() }}

This is the answer I provided some time ago here.

And here is the documentation from Laravel for that