Contextual date functionality in Laravel.
joshbrw/laravel-contextual-dates is a Laravel package for contextual date functionality in laravel..
It currently has 0 GitHub stars and 2.919 downloads on Packagist (latest version v0.1.4).
Install it with composer require joshbrw/laravel-contextual-dates.
Discover more Laravel packages by joshbrw
or browse all Laravel packages to compare alternatives.
Last updated
composer require joshbrw/laravel-contextual-datesconfig/app.php:
Joshbrw\LaravelContextualDates\ContextualDatesServiceProvider::classDateTimeFactory with the desired Timezone and Formats. These formats can be named whatever you like, i.e. long or short.FormatsDates trait or the helpers defined in helpers.php to localize/output the dates.Two date formats are provided by default, long and short. These can be over-ridden at any time.
The DateTimeFactory is bound as a singleton in the container, so it can be picked up and modified at any time (similar to the inbuilt View/Validation factories that Laravel provides).
$dateTimeFactory = app(DateTimeFactory::class);
$dateTimeFactory->addFormat('mixed', 'Y-m-d');
$carbon = new \Carbon\Carbon;
$dateTime = $dateTimeFactory->createFromCarbon($carbon);
echo $dateTime->format('mixed'); /* Outputs in Y-m-d */
This package ships with two helper methods; localize_date() and format_date().
$dateTimeFactory = app(DateTimeFactory::class);
$dateTimeFactory->addFormat('mixed', 'Y-m-d');
$carbon = new \Carbon\Carbon;
$instance = localize_date($carbon); /* Instance of DateTime */
echo format_date($carbon, 'mixed'); /* Outputs in Y-m-d */
You can format dates in the Views using the Blade Directive. All this does is proxy to the format_date() helper method.
@date(new Carbon, 'long')