src/app/Traits/Sluggable.php
public function createSlug($value, $id = 0)
    {
        $slug = str_slug($value);

        $relatedSlugs = $this->getRelatedSlugs($slug, $id);

        if (!$relatedSlugs->contains('slug', $slug)) {
            return $slug;
        }

        $completed = false;
        $i = 1;

        while ($completed == false) {
            $newSlug = $slug .'-'.$i;
            if (!$relatedSlugs->contains('slug', $newSlug)) {
                return $newSlug;
            }
            $i++;
        }

        return $slug;
    }
public function createSlug($value, $id = 0)
    {
        $slug = str_slug($value);

        $relatedSlugs = $this->getRelatedSlugs($slug, $id);

        if (!$relatedSlugs->contains('slug', $slug)) {
            return $slug;
        }

        $completed = false;
        $i = 1;

        while ($completed == false) {
            $newSlug = $slug .'-'.$i;
            if (!$relatedSlugs->contains('slug', $newSlug)) {
                return $newSlug;
            }
            $i++;
        }

        return $slug;
    }
public function createSlug ( $ value , $ id = 0 ) { $ slug = str_slug ( $ value ) ; $ relatedSlugs = $ this -> getRelatedSlugs ( $ slug , $ id ) ; if ( ! $ relatedSlugs -> contains ( 'slug' , $ slug ) ) { return $ slug ; } $ completed = false ; $ i = 1 ; while ( $ completed == false ) { $ newSlug = $ slug . '-' . $ i ; if ( ! $ relatedSlugs -> contains ( 'slug' , $ newSlug ) ) { return $ newSlug ; } $ i ++ ; } return $ slug ; }
Create a unique slug
@param $value
@param $id
@return string
Create a unique slug