public static function checkSlug($slugField, $slug, $id = null)
    {
        $instance   = new static;

        $slug   = $slug;
        $query = $instance->where($slugField, $slug);

        if($id != null)
        {
            $query->whereNotIn($instance->getKeyName(), [$id]);
        }

        $nObjects = $query->count();

        if($nObjects > 0)
        {
            $suffix = 0;
            while($nObjects > 0)
            {
                $suffix++;
                $slug       = $slug . '-' . $suffix;
                $nObjects   = $instance->where($slugField, $slug)->count();
            }
        }

        return $slug;
    }
public static function checkSlug($slugField, $slug, $id = null)
    {
        $instance   = new static;

        $slug   = $slug;
        $query = $instance->where($slugField, $slug);

        if($id != null)
        {
            $query->whereNotIn($instance->getKeyName(), [$id]);
        }

        $nObjects = $query->count();

        if($nObjects > 0)
        {
            $suffix = 0;
            while($nObjects > 0)
            {
                $suffix++;
                $slug       = $slug . '-' . $suffix;
                $nObjects   = $instance->where($slugField, $slug)->count();
            }
        }

        return $slug;
    }
public static function checkSlug ( $ slugField , $ slug , $ id = null ) { $ instance = new static ; $ slug = $ slug ; $ query = $ instance -> where ( $ slugField , $ slug ) ; if ( $ id != null ) { $ query -> whereNotIn ( $ instance -> getKeyName ( ) , [ $ id ] ) ; } $ nObjects = $ query -> count ( ) ; if ( $ nObjects > 0 ) { $ suffix = 0 ; while ( $ nObjects > 0 ) { $ suffix ++ ; $ slug = $ slug . '-' . $ suffix ; $ nObjects = $ instance -> where ( $ slugField , $ slug ) -> count ( ) ; } } return $ slug ; }
Function to check if slug exists

@access  public
@param   string          $slugField
@param   string          $slug
@param   integer|string  $id
@return  string          $slug
Function to check if slug exists