2017 © Pedro Peláez
 

library laravel-contextual-dates

Contextual date functionality in Laravel.

image

joshbrw/laravel-contextual-dates

Contextual date functionality in Laravel.

  • Thursday, September 14, 2017
  • by joshbrw
  • Repository
  • 1 Watchers
  • 0 Stars
  • 608 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 16 % Grown

The README.md

Laravel Contextual Dates

Installation

  1. Install the package via Composer: composer require joshbrw/laravel-contextual-dates
  2. Add the Service Provider to config/app.php: Joshbrw\LaravelContextualDates\ContextualDatesServiceProvider::class
  3. Configure the DateTimeFactory with the desired Timezone and Formats. These formats can be named whatever you like, i.e. long or short.
  4. Use the FormatsDates trait or the helpers defined in helpers.php to localize/output the dates.

Defaults

Two date formats are provided by default, long and short. These can be over-ridden at any time., (*1)

Examples

Using Container

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)., (*2)

$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 */

Using Helpers

This package ships with two helper methods; localize_date() and format_date()., (*3)

$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 */

Using Blade Directive

You can format dates in the Views using the Blade Directive. All this does is proxy to the format_date() helper method., (*4)

@date(new Carbon, 'long')

The Versions

14/09 2017

dev-master

9999999-dev

Contextual date functionality in Laravel.

  Sources   Download

MIT

The Requires

 

by Josh Brown

14/09 2017

v0.1.4

0.1.4.0

Contextual date functionality in Laravel.

  Sources   Download

MIT

The Requires

 

by Josh Brown

20/03 2017

v0.1.3

0.1.3.0

Contextual date functionality in Laravel.

  Sources   Download

MIT

The Requires

 

by Josh Brown

20/03 2017

v0.1.2

0.1.2.0

Contextual date functionality in Laravel.

  Sources   Download

MIT

The Requires

 

by Josh Brown

20/03 2017

v0.1.1

0.1.1.0

Contextual date functionality in Laravel.

  Sources   Download

MIT

The Requires

 

by Josh Brown

20/03 2017

v0.1

0.1.0.0

Contextual date functionality in Laravel.

  Sources   Download

MIT

The Requires

 

by Josh Brown