Small macro for a read duration, laravel

Home   »   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';

Leave a Reply

Your email address will not be published.