src/Services/SlugService.php
protected function validateSlug(string $slug, array $config, string $attribute): string
    {
        $separator = $config['separator'];
        $reserved = $config['reserved'];

        if ($reserved === null) {
            return $slug;
        }

        // check for reserved names
        if ($reserved instanceof \Closure) {
            $reserved = $reserved($this->model);
        }

        if (is_array($reserved)) {
            if (in_array($slug, $reserved)) {
                $method = $config['uniqueSuffix'];
                if ($method === null) {
                    $suffix = $this->generateSuffix($slug, $separator, collect($reserved));
                } elseif (is_callable($method)) {
                    $suffix = $method($slug, $separator, collect($reserved));
                } else {
                    throw new \UnexpectedValueException('Sluggable "uniqueSuffix" for ' . get_class($this->model) . ':' . $attribute . ' is not null, or a closure.');
                }

                return $slug . $separator . $suffix;
            }

            return $slug;
        }

        throw new \UnexpectedValueException('Sluggable "reserved" for ' . get_class($this->model) . ':' . $attribute . ' is not null, an array, or a closure that returns null/array.');
    }
protected function validateSlug(string $slug, array $config, string $attribute): string
    {
        $separator = $config['separator'];
        $reserved = $config['reserved'];

        if ($reserved === null) {
            return $slug;
        }

        // check for reserved names
        if ($reserved instanceof \Closure) {
            $reserved = $reserved($this->model);
        }

        if (is_array($reserved)) {
            if (in_array($slug, $reserved)) {
                $method = $config['uniqueSuffix'];
                if ($method === null) {
                    $suffix = $this->generateSuffix($slug, $separator, collect($reserved));
                } elseif (is_callable($method)) {
                    $suffix = $method($slug, $separator, collect($reserved));
                } else {
                    throw new \UnexpectedValueException('Sluggable "uniqueSuffix" for ' . get_class($this->model) . ':' . $attribute . ' is not null, or a closure.');
                }

                return $slug . $separator . $suffix;
            }

            return $slug;
        }

        throw new \UnexpectedValueException('Sluggable "reserved" for ' . get_class($this->model) . ':' . $attribute . ' is not null, an array, or a closure that returns null/array.');
    }
protected function validateSlug ( string $ slug , array $ config , string $ attribute ) : string { $ separator = $ config [ 'separator' ] ; $ reserved = $ config [ 'reserved' ] ; if ( $ reserved === null ) { return $ slug ; } // check for reserved names if ( $ reserved instanceof \ Closure ) { $ reserved = $ reserved ( $ this -> model ) ; } if ( is_array ( $ reserved ) ) { if ( in_array ( $ slug , $ reserved ) ) { $ method = $ config [ 'uniqueSuffix' ] ; if ( $ method === null ) { $ suffix = $ this -> generateSuffix ( $ slug , $ separator , collect ( $ reserved ) ) ; } elseif ( is_callable ( $ method ) ) { $ suffix = $ method ( $ slug , $ separator , collect ( $ reserved ) ) ; } else { throw new \ UnexpectedValueException ( 'Sluggable "uniqueSuffix" for ' . get_class ( $ this -> model ) . ':' . $ attribute . ' is not null, or a closure.' ) ; } return $ slug . $ separator . $ suffix ; } return $ slug ; } throw new \ UnexpectedValueException ( 'Sluggable "reserved" for ' . get_class ( $ this -> model ) . ':' . $ attribute . ' is not null, an array, or a closure that returns null/array.' ) ; }
Checks that the given slug is not a reserved word.

@param string $slug
@param array $config
@param string $attribute

@return string
@throws \UnexpectedValueException
Checks that the given slug is not a reserved word .