protected function makeSlugUnique($slug)
    {
        $i = 1;
        $slugIsUnique = false;

        // get existing slugs (1 db query)
        $list = $this->getExistingSlugs($slug);

        // slug is already unique
        if ($list->count() === 0) {
            return $slug;
        }

        // collection to array
        if (!is_array($list)) {
            $list = $list->toArray();
        }

        // loop through the list and add suffix
        while (!$slugIsUnique) {
            $uniqueSlug = $slug . $this->slugOptions->slugSeparator . ($i++);
            if (!in_array($uniqueSlug, $list)) {
                $slugIsUnique = true;
            }
        }

        return $uniqueSlug;
    }
protected function makeSlugUnique($slug)
    {
        $i = 1;
        $slugIsUnique = false;

        // get existing slugs (1 db query)
        $list = $this->getExistingSlugs($slug);

        // slug is already unique
        if ($list->count() === 0) {
            return $slug;
        }

        // collection to array
        if (!is_array($list)) {
            $list = $list->toArray();
        }

        // loop through the list and add suffix
        while (!$slugIsUnique) {
            $uniqueSlug = $slug . $this->slugOptions->slugSeparator . ($i++);
            if (!in_array($uniqueSlug, $list)) {
                $slugIsUnique = true;
            }
        }

        return $uniqueSlug;
    }
protected function makeSlugUnique ( $ slug ) { $ i = 1 ; $ slugIsUnique = false ; // get existing slugs (1 db query) $ list = $ this -> getExistingSlugs ( $ slug ) ; // slug is already unique if ( $ list -> count ( ) === 0 ) { return $ slug ; } // collection to array if ( ! is_array ( $ list ) ) { $ list = $ list -> toArray ( ) ; } // loop through the list and add suffix while ( ! $ slugIsUnique ) { $ uniqueSlug = $ slug . $ this -> slugOptions -> slugSeparator . ( $ i ++ ) ; if ( ! in_array ( $ uniqueSlug , $ list ) ) { $ slugIsUnique = true ; } } return $ uniqueSlug ; }
Make the slug unique with suffix
@param $slug
@return string
Make the slug unique with suffix