Laravel Packagev13.xMIT License87.2K+ downloads

Readable: Raw values, human words

Readable numbers, dates and sizes in Laravel, zero setup. Print 77.7K, 1.5 KB or 3 months 29 minutes with @readableCompactNumber, @readableFileSize and @readableDuration.

$composer require pharaonic/laravel-readable
Key Features

Everything you need to print values for humans

No configuration. Call a method, a helper or a Blade directive.

Numbers

Group thousands (10,203,040), shorten (77.7K), keep decimals only when they matter (70, 70.07).

Numbers in Words

7721 becomes seven thousand seven hundred twenty-one, in English without intl or any language with it.

Dates & Times

24 April 2020, 03:20 PM or Friday, April 24, 2020 05:20 PM, in any timezone.

Differences

29 years before, or the full 29 years 2 months 3 days ... between any two dates.

File Sizes

Decimal (1.5 KB) or binary (7 KiB) units, from bytes up to yottabytes.

Three Ways to Call

Readable::getFileSize(), readable_file_size() or @readableFileSize(), with the same arguments.

A quick look

Every formatter is a Blade directive, a global helper and a static method.

resources/views/files/show.blade.php
1<h1>{{ $file->name }}</h1>
2 
3<p>Size: @readableFileSize($file->size)</p> {{-- 1.5 KB --}}
4<p>Downloads: @readableCompactNumber($file->downloads)</p> {{-- 77K --}}
5<p>Uploaded: @readableDate($file->created_at)</p> {{-- 24 April 2020 --}}
6<p>@readableRelativeDateTime($file->updated_at)</p> {{-- 2 hours before --}}
7 
8{{-- Or in PHP --}}
9{{ readable_file_size($file->size, false) }} {{-- 1.46 KiB --}}
FAQ

Readable Questions

Quick answers about installing and using Readable.

What is Readable?

Human-readable numbers, dates, durations and file sizes for Laravel, as static methods, helpers and Blade directives. It's a free, open-source Laravel package by Pharaonic.

How do I install Readable?

Run composer require pharaonic/laravel-readable in your project's root directory.

What does Readable require?

The latest release requires PHP 8.3+ and Laravel 13.

Do I need the intl extension?

Only to spell numbers in a language other than English, such as readable_number_in_words(21, 'ar'). English spelling and every other formatter work without it.

Are dates and durations translated?

Yes. Month names, day names and words such as years and before come from Carbon, which follows your application locale.

Why does `readable_compact_number(1500)` print `1K`?

Without decimals the value is truncated to whole units, so a counter never shows more than it has. Pass true to show a rounded decimal: readable_compact_number(1500, true) prints 1.5K.

Is the Blade output escaped?

No. The directives echo the result as is, like {!! !!}, so you can pass HTML entities as a delimiter. Don't pass user input as a delimiter.

Is Readable free to use?

Yes. Readable is open source under the MIT license, so you can use it in personal and commercial projects.

Where can I find the Readable documentation?

Read the Readable documentation for setup, configuration, and usage examples.

How do I report a bug or contribute to Readable?

Open an issue or a pull request on GitHub, or ask in the Pharaonic Discord.

Ready to dig in?

Read the full documentation for installation, readable numbers, numbers in words, dates and times, date differences, durations, file sizes, the global helpers, the Blade directives, upgrading from 1.x, and real-world examples.