PHPackages                             leshkens/laravel-read-time - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. leshkens/laravel-read-time

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

leshkens/laravel-read-time
==========================

A package for laravel framework that shows users the approximate time to read content.

v1.5.0(1y ago)33.9k↓37.5%31MITPHPPHP ^7.2.5|^8.0

Since Mar 31Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Leshkens/laravel-read-time)[ Packagist](https://packagist.org/packages/leshkens/laravel-read-time)[ Docs](https://github.com/leshkens/laravel-read-time)[ RSS](/packages/leshkens-laravel-read-time/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (3)Versions (9)Used By (1)

Laravel read time package
=========================

[](#laravel-read-time-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c42ec1e282a1390f0a75a47265b3bd2b69e219a4968c0d3f58f1c6269c2caf02/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6573686b656e732f6c61726176656c2d726561642d74696d652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/leshkens/laravel-read-time)[![Total Downloads](https://camo.githubusercontent.com/f5f3819bfd4a1e9f8708512871156983cf5e84db4fb0fd6a4c21c1d2e99a9fce/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6573686b656e732f6c61726176656c2d726561642d74696d652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/leshkens/laravel-read-time)

A package for laravel that shows users the approximate time to read content.

[![img.png](https://user-images.githubusercontent.com/8939383/113155120-24f5e380-9252-11eb-95ec-402f4cf3a2e4.png)](https://user-images.githubusercontent.com/8939383/113155120-24f5e380-9252-11eb-95ec-402f4cf3a2e4.png)

### Requirements

[](#requirements)

- Laravel version 6 or higher

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require leshkens/laravel-read-time
```

### Publish config file

[](#publish-config-file)

```
php artisan vendor:publish --provider="Leshkens\LaravelReadTime\Providers\ReadTimeServiceProvider"
```

Config file `config/read-time.php`
----------------------------------

[](#config-file-configread-timephp)

### Global options:

[](#global-options)

```
'options' => [
    // The number of words per minute, based on which the approximate
    // time for reading will be calculated. Default is 230
    'words_per_minute' => 230,

    // Clear result string of html tags
    'strip_tags' => false,

    // How many seconds does a new unit start with
    'units' => [
        'second' => 0,
        'minute' => 60,
        //'hour'   => 3600
    ]
],
```

### Word counter class

[](#word-counter-class)

```
'counter' => Leshkens\LaravelReadTime\Counter::class,
```

You can use your class and logic in word counting. Your class must implement the `Leshkens\LaravelReadTime\Contracts\CounterInterface` interface. The logic should be in the `count()` method.

For example, this is what a standard word counter logic looks like:

```
public function count(string $content): int
{
    return count(preg_split('/\s+/', $content, -1, PREG_SPLIT_NO_EMPTY));
}
```

### Locale list

[](#locale-list)

List of locales for forming the string "time to read":

```
'locales' => [
    'en' => Leshkens\LaravelReadTime\Locales\En::class
]
```

Locale class must implement the `Leshkens\LaravelReadTime\Contracts\LocaleInterface` interface. The logic should be in the `result()` method.

For example, let's add the Ru locale class:

```
namespace App\Support\ReadTimeLocales;

use Leshkens\LaravelReadTime\Contracts\LocaleInterface;
use function morphos\Russian\pluralize;

class Ru implements LocaleInterface
{
    protected $unitMap = [
        'second' => 'секунда',
        'minute' => 'минута',
        'hour'   => 'час'
    ];

    public function result(int $number, string $unit): string
    {
        return pluralize($number, $this->unitMap[$unit]);
    }
}
```

In config:

```
'locales' => [
    'en' => Leshkens\LaravelReadTime\Locales\En::class,
    'ru' => App\Support\ReadTimeLocales\Ru::class
]
```

Usage
-----

[](#usage)

### Object

[](#object)

```
use Illuminate\Support\Str;
use Leshkens\LaravelReadTime\Facades\ReadTime;

$readTime = ReadTime::parse('Lorem ipsum dolor sit amet, consectetur adipiscing elit...');
// Or array
$readTime = ReadTime::parse(['Lorem ipsum dolor sit amet', 'consectetur adipiscing elit']);

$number = $readTime->number; // 3
$unit   = $readTime->unit;   // second

$result = Str::plural($unit, $number);

return "{$number} {$result} on read"; // 3 seconds on read
```

You can pass your array of settings (the same settings as the global ones) as the second argument of the `ReadTime` object.

Example:

```
$options = [
    'words_per_minute' => 1,
    'units'            => [
        'second' => 1 // leave only a seconds
    ]
];

$readTime = ReadTime::parse('Lorem ipsum dolor sit amet, consectetur adipiscing elit...', $options);

$number = $readTime->number; // 3
$unit   = $readTime->unit;   // second

$result = Str::plural($unit, $number);

return "{$number} {$result} on read"; // 480 seconds on read
```

### String

[](#string)

Just add the `get()` method.

The method can take a locale (from package config locale list) string value as the first argument. If nothing is passed to the method, or the value is null, the current application locale is taken.

```
use Leshkens\LaravelReadTime\Facades\ReadTime;

ReadTime::parse('Lorem ipsum dolor sit amet, consectetur adipiscing elit...')
    ->get('ru');
```

Will return `3 секунды`

**Note:** If the object of the desired locale is not in the config file of the package, then by default the string for English will be output

You can also use the `readtime()` helper to render a string:

```
readtime($content, $locale, $options);
```

### In model

[](#in-model)

Add the `HasReadTime` trait and `readTime()` method with settings to your model:

```
use Illuminate\Database\Eloquent\Model;
use Leshkens\LaravelReadTime\Traits\HasReadTime;

class Article extends Model
{
    use HasReadTime;

    protected function readTime(): array
    {
        return [
            // Attribute for parse. You can split it with
            // a dot (e.g 'content.text') if the desired
            // attribute is inside a array or json
            'source' => 'content',

            // No required. If this key is not present, then the current application locale is taken.
            'locale' => 'en',

            // No required. Options array.
            'options' => [
                'strip_tags' => true
            ]
        ];
    }
}
```

`$article->read_time` returns the string value of the time to read.

If your attribute contains an array or json with locales:

```
// array
[
    'ru' => 'Какой-то прекрасный текст',
    'en' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
]

// or json
{
    "ru": "Какой-то прекрасный текст",
    "en": "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
}
```

you can set `localable` to `true`:

```
protected function readTime(): array
{
    return [
        'source'    => 'content',
        'localable' => true
    ];
}
```

`$article->read_time` returns the array value:

```
[
  'ru' => '1 секунда'
  'en' => '3 seconds on read'
]
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Alexey Chugunov](https://github.com/leshkens)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance44

Moderate activity, may be stable

Popularity27

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 85.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~204 days

Recently: every ~233 days

Total

8

Last Release

445d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/454487fa0eb113883aab5089cd891316fb9d2d17c835c230e631c6a82500d231?d=identicon)[Achugunov](/maintainers/Achugunov)

---

Top Contributors

[![Leshkens](https://avatars.githubusercontent.com/u/8939383?v=4)](https://github.com/Leshkens "Leshkens (18 commits)")[![officialkidmax](https://avatars.githubusercontent.com/u/41998473?v=4)](https://github.com/officialkidmax "officialkidmax (2 commits)")[![batinmustu](https://avatars.githubusercontent.com/u/74476363?v=4)](https://github.com/batinmustu "batinmustu (1 commits)")

---

Tags

laravelcontenttimereadblogarticlereadingMinuteslaravel-read-timeachugunov

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/leshkens-laravel-read-time/health.svg)

```
[![Health](https://phpackages.com/badges/leshkens-laravel-read-time/health.svg)](https://phpackages.com/packages/leshkens-laravel-read-time)
```

###  Alternatives

[mtownsend/read-time

A PHP package to show users how long it takes to read content.

283571.1k2](/packages/mtownsend-read-time)[stephenjude/filament-blog

Filament Blog Builder

20317.8k](/packages/stephenjude-filament-blog)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[maherelgamil/arabicdatetime

Easy and useful tool to generate arabic or hijri date with multi-language support for laravel

414.5k](/packages/maherelgamil-arabicdatetime)[diego-ninja/sentinel

A content moderation and sentiment analysis library for Laravel 10+

384.3k](/packages/diego-ninja-sentinel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
