Skip to content

Instantly share code, notes, and snippets.

@nezaboravi
Created May 5, 2021 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nezaboravi/ee7e0b9ef599315f347107a4047c1534 to your computer and use it in GitHub Desktop.
Save nezaboravi/ee7e0b9ef599315f347107a4047c1534 to your computer and use it in GitHub Desktop.
Small macro for a read duration, laravel
Str::macro('readDuration', function( ...$text) {
$totalWords = str_word_count(implode(' ', $text));
$minutesToRead = round($totalWorlds / 200);
return (int) max(1, $minutesToRead);
});
echo Str::readDuration($post->text) . ' min read';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment