Skip to content

Instantly share code, notes, and snippets.

View MohcinBN's full-sized avatar

Mohcin Bounouara MohcinBN

View GitHub Profile
@MohcinBN
MohcinBN / reading-time.php
Last active November 13, 2022 14:17
Laravel 9 reading time for yuour posts
// add this function to your post model;
// reading time
//The average reader reads about 200 words per minute, so I decided to have less to make estimates more accurate
public function postReadingTimeEstimation($averageReadsPerMunite = 180)
{
$textOfTheBody = $this->body;
$totalWords = str_word_count(strip_tags($textOfTheBody));
$minutes = floor($totalWords / $averageReadsPerMunite);