public function checkIfSlugIsUnique($slug)
    {
        $i = 0;
        $this->base_slug = $slug;

        while ($this->post->whereSlug($slug)->get()->count() > 0) {
            $i++;
            $slug = "$this->base_slug-$i";
        }

        return $slug;
    }
public function checkIfSlugIsUnique($slug)
    {
        $i = 0;
        $this->base_slug = $slug;

        while ($this->post->whereSlug($slug)->get()->count() > 0) {
            $i++;
            $slug = "$this->base_slug-$i";
        }

        return $slug;
    }
public function checkIfSlugIsUnique ( $ slug ) { $ i = 0 ; $ this -> base_slug = $ slug ; while ( $ this -> post -> whereSlug ( $ slug ) -> get ( ) -> count ( ) > 0 ) { $ i ++ ; $ slug = "$this->base_slug-$i" ; } return $ slug ; }
Check if a given slug already exists
and when it exists generate a new one

@param string $slug
@return string
Check if a given slug already exists and when it exists generate a new one