src/Titon/Db/Behavior/SlugBehavior.php
public function makeUnique($id, $slug) {
        $repo = $this->getRepository();
        $scope = $this->getConfig('scope');

        /** @type \Titon\Db\Query $query */
        foreach ([
            $repo->select()->where($this->getConfig('slug'), $slug),
            $repo->select()->where($this->getConfig('slug'), 'like', $slug . '%')
        ] as $i => $query) {
            if ($scope) {
                $query->bindCallback($scope);
            }

            if ($id) {
                $query->where($repo->getPrimaryKey(), '!=', $id);
            }

            $count = $query->count();

            if ($count <= 0) {
                break;

            } else if ($i) {
                return $slug . '-' . $count;
            }
        }

        return $slug;
    }
public function makeUnique($id, $slug) {
        $repo = $this->getRepository();
        $scope = $this->getConfig('scope');

        /** @type \Titon\Db\Query $query */
        foreach ([
            $repo->select()->where($this->getConfig('slug'), $slug),
            $repo->select()->where($this->getConfig('slug'), 'like', $slug . '%')
        ] as $i => $query) {
            if ($scope) {
                $query->bindCallback($scope);
            }

            if ($id) {
                $query->where($repo->getPrimaryKey(), '!=', $id);
            }

            $count = $query->count();

            if ($count <= 0) {
                break;

            } else if ($i) {
                return $slug . '-' . $count;
            }
        }

        return $slug;
    }
public function makeUnique ( $ id , $ slug ) { $ repo = $ this -> getRepository ( ) ; $ scope = $ this -> getConfig ( 'scope' ) ; /** @type \Titon\Db\Query $query */ foreach ( [ $ repo -> select ( ) -> where ( $ this -> getConfig ( 'slug' ) , $ slug ) , $ repo -> select ( ) -> where ( $ this -> getConfig ( 'slug' ) , 'like' , $ slug . '%' ) ] as $ i => $ query ) { if ( $ scope ) { $ query -> bindCallback ( $ scope ) ; } if ( $ id ) { $ query -> where ( $ repo -> getPrimaryKey ( ) , '!=' , $ id ) ; } $ count = $ query -> count ( ) ; if ( $ count <= 0 ) { break ; } else if ( $ i ) { return $ slug . '-' . $ count ; } } return $ slug ; }
Validate the slug is unique by querying for other slugs.
If the slug is not unique, append a count to it.

@param int|int[] $id
@param string $slug
@return string
Validate the slug is unique by querying for other slugs . If the slug is not unique append a count to it .