Created
January 4, 2022 09:53
-
-
Save adinata-id/aa5f1fab092a9df8b32053a36b8271b4 to your computer and use it in GitHub Desktop.
Read Duration Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//tambahkan pada AppService Provider | |
Str::macro('readDuration', function (...$text) { | |
$totalWords = str_word_count(implode(" ", $text)); | |
$minutesToRead = round($totalWords / 200); | |
return (int)max(1, $minutesToRead); | |
}); | |
//implementasi pada laravel blade | |
<span class="uppercase"> | |
{{ Str::readDuration ($article->title,$article->content) . ' min read'}} | |
</span> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment