src/Services/SlugService.php
protected function generateSuffix(string $slug, string $separator, Collection $list): string
    {
        $len = strlen($slug . $separator);

        // If the slug already exists, but belongs to
        // our model, return the current suffix.
        if ($list->search($slug) === $this->model->getKey()) {
            $suffix = explode($separator, $slug);

            return end($suffix);
        }

        $list->transform(function($value, $key) use ($len) {
            return (int) substr($value, $len);
        });

        // find the highest value and return one greater.
        return $list->max() + 1;
    }
protected function generateSuffix(string $slug, string $separator, Collection $list): string
    {
        $len = strlen($slug . $separator);

        // If the slug already exists, but belongs to
        // our model, return the current suffix.
        if ($list->search($slug) === $this->model->getKey()) {
            $suffix = explode($separator, $slug);

            return end($suffix);
        }

        $list->transform(function($value, $key) use ($len) {
            return (int) substr($value, $len);
        });

        // find the highest value and return one greater.
        return $list->max() + 1;
    }
protected function generateSuffix ( string $ slug , string $ separator , Collection $ list ) : string { $ len = strlen ( $ slug . $ separator ) ; // If the slug already exists, but belongs to // our model, return the current suffix. if ( $ list -> search ( $ slug ) === $ this -> model -> getKey ( ) ) { $ suffix = explode ( $ separator , $ slug ) ; return end ( $ suffix ) ; } $ list -> transform ( function ( $ value , $ key ) use ( $ len ) { return ( int ) substr ( $ value , $ len ) ; } ) ; // find the highest value and return one greater. return $ list -> max ( ) + 1 ; }
Generate a unique suffix for the given slug (and list of existing, "similar" slugs.

@param string $slug
@param string $separator
@param \Illuminate\Support\Collection $list

@return string
Generate a unique suffix for the given slug ( and list of existing similar slugs .