まず、phpの日付関数
Route::get('/dates', function(){ $date = new DateTime('+1 week'); echo $date->format('m-d-Y'); });
続いてCarbon
composerで探します
$ php composer.phar search carbon
nesbot/carbon A simple API extension for DateTime.
nesbot/carbon An API extension for DateTime that supports 281 different languages.
anyway, laravelはdefaultでcarbonはincludeされています。
use Carbon\Carbonでクラスを指定すれば、すぐに使えます。
carbon
use Carbon\Carbon; Route::get('/dates', function(){ $date = new DateTime('+1 week'); echo $date->format('m-d-Y') . "<br>"; echo Carbon::now(); echo '<br>'; echo Carbon::now()->addDays(10)->diffForHumans(); echo '<br>'; echo Carbon::now()->subMonths(5)->diffForHumans(); echo '<br>'; echo Carbon::now()->yesterday()->diffForHumans(); echo '<br>'; });