Laravel Packages

Standardize Data Formats in Your Laravel Application

Published
Standardize Data Formats in Your Laravel Application image

Laravel Formatters is a package by Michael Rubel that provides a collection of classes you can use to standardize data formats in your Laravel application:

use MichaelRubel\Formatters\Collection\DateFormatter;
use MichaelRubel\Formatters\Collection\DateTimeFormatter;
use MichaelRubel\Formatters\Collection\LocaleNumberFormatter;
use MichaelRubel\Formatters\Collection\TableColumnFormatter;
 
 
format(DateFormatter::class, now())
// "2021-11-09"
 
format(DateTimeFormatter::class, now())
// "2021-11-09 02:28"
 
format(LocaleNumberFormatter::class, 1)
// "1.00"
 
config()->set('app.locale', 'es');
format(LocaleNumberFormatter::class, 1);
// "1,00"
 
format(TableColumnFormatter::class, 'created_at')
// "Created at"

If you want to extend a built-in formatter provided by this package, you can extend the service provider definition to override it:

use MichaelRubel\Formatters\Collection\DateTimeFormatter;
 
$this->app->extend(DateTimeFormatter::class, function ($formatter) {
$formatter->datetime_format = 'Y.m.d H:i';
 
return $formatter;
});

You can learn more about this package, get full installation instructions, and view the source code on GitHub.


This package was submitted to our Laravel News Links section. Links is a place the community can post packages and tutorials around the Laravel ecosystem. Follow along on Twitter @LaravelLinks

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

tinkerwell logo
Tinkerwell

Enjoy coding and debugging in an editor designed for fast feedback and quick iterations. It's like a shell for your application – but with multi-line editing, code completion, and more.

Visit Tinkerwell

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article