public function generateSlug($title, $tableName, $primaryKey, $languageSlug = '', $id = 0, $translatable = false,
        $hasVirtualSlug = false, $delimiter = "-"
    ) {
        $count = 0;
        $found = true;
        $originalSlug = str_slug($title, $delimiter);

        while($found){
            if($count != 0) {
                $slug = $originalSlug.$delimiter.$count;
            }else{
                $slug = $originalSlug;
            }

            $countObj = DB::table($tableName);
            if ($translatable) {
                if($hasVirtualSlug) {
                    $countObj->where('slug_'.$languageSlug, $slug);
                }else{
                    $countObj->where('slug->'.$languageSlug, $slug);
                }
            }else{
                $countObj->where('slug', $slug);
            }
            if($id) {
                $countObj->where($primaryKey, '!=', $id);
            }
            $countPosts = $countObj->count();

            if(!$countPosts) {
                return $slug;
            }
            $count++;
        }
        return $originalSlug;
    }
public function generateSlug($title, $tableName, $primaryKey, $languageSlug = '', $id = 0, $translatable = false,
        $hasVirtualSlug = false, $delimiter = "-"
    ) {
        $count = 0;
        $found = true;
        $originalSlug = str_slug($title, $delimiter);

        while($found){
            if($count != 0) {
                $slug = $originalSlug.$delimiter.$count;
            }else{
                $slug = $originalSlug;
            }

            $countObj = DB::table($tableName);
            if ($translatable) {
                if($hasVirtualSlug) {
                    $countObj->where('slug_'.$languageSlug, $slug);
                }else{
                    $countObj->where('slug->'.$languageSlug, $slug);
                }
            }else{
                $countObj->where('slug', $slug);
            }
            if($id) {
                $countObj->where($primaryKey, '!=', $id);
            }
            $countPosts = $countObj->count();

            if(!$countPosts) {
                return $slug;
            }
            $count++;
        }
        return $originalSlug;
    }
public function generateSlug ( $ title , $ tableName , $ primaryKey , $ languageSlug = '' , $ id = 0 , $ translatable = false , $ hasVirtualSlug = false , $ delimiter = "-" ) { $ count = 0 ; $ found = true ; $ originalSlug = str_slug ( $ title , $ delimiter ) ; while ( $ found ) { if ( $ count != 0 ) { $ slug = $ originalSlug . $ delimiter . $ count ; } else { $ slug = $ originalSlug ; } $ countObj = DB :: table ( $ tableName ) ; if ( $ translatable ) { if ( $ hasVirtualSlug ) { $ countObj -> where ( 'slug_' . $ languageSlug , $ slug ) ; } else { $ countObj -> where ( 'slug->' . $ languageSlug , $ slug ) ; } } else { $ countObj -> where ( 'slug' , $ slug ) ; } if ( $ id ) { $ countObj -> where ( $ primaryKey , '!=' , $ id ) ; } $ countPosts = $ countObj -> count ( ) ; if ( ! $ countPosts ) { return $ slug ; } $ count ++ ; } return $ originalSlug ; }
This function creates the slug for a row of a model and makes sure that
slugs it is not being used from a other post.

@param  string $title
@param  string $tableName
@param  int    $primaryKey
@param  string $languageSlug
@param  int    $id
@param  bool   $translatable
@param  bool   $hasVirtualSlug
@param  string $delimiter
@return string
This function creates the slug for a row of a model and makes sure that slugs it is not being used from a other post .