public static function insertTags($selectedTags, $postID, $postType)
    {
        if(count($selectedTags)) {
            $tagsIDs = [];

            $newTagsRelations = [];
            foreach ($selectedTags as $langSlug => $selectedTagForLanguage){
                if($selectedTagForLanguage) {
                    foreach ($selectedTagForLanguage as $selectedTag){

                        //insert tag if it doesn't exist
                        if($selectedTag['tagID'] == 0) {
                            $tagSlug = str_slug($selectedTag['title'], '-');
                            $tagsID = DB::table('tags')->insertGetId(
                                [
                                'postTypeID' => $postType['postTypeID'],
                                'createdByUserID' => Auth::user()->userID,
                                'title' => $selectedTag['title'],
                                'description' => $selectedTag['description'],
                                'slug' => $tagSlug,
                                ]
                            );
                        }else{
                            $tagsID = $selectedTag['tagID'];
                        }

                        //add new tag relationship
                        $newTagsRelations[] = [
                          'tagID' => $tagsID,
                          'postID' => $postID,
                          'language' => $langSlug
                        ];
                        $tagsIDs[] = $tagsID;
                    }
                }
            }

            // if post is in the main database
            $insertedTags = (new TagRelation())->setTable($postType->slug.'_tags')->insert($newTagsRelations);
            if($insertedTags) {
                return $tagsIDs;
            }
        }
        return [];
    }
public static function insertTags($selectedTags, $postID, $postType)
    {
        if(count($selectedTags)) {
            $tagsIDs = [];

            $newTagsRelations = [];
            foreach ($selectedTags as $langSlug => $selectedTagForLanguage){
                if($selectedTagForLanguage) {
                    foreach ($selectedTagForLanguage as $selectedTag){

                        //insert tag if it doesn't exist
                        if($selectedTag['tagID'] == 0) {
                            $tagSlug = str_slug($selectedTag['title'], '-');
                            $tagsID = DB::table('tags')->insertGetId(
                                [
                                'postTypeID' => $postType['postTypeID'],
                                'createdByUserID' => Auth::user()->userID,
                                'title' => $selectedTag['title'],
                                'description' => $selectedTag['description'],
                                'slug' => $tagSlug,
                                ]
                            );
                        }else{
                            $tagsID = $selectedTag['tagID'];
                        }

                        //add new tag relationship
                        $newTagsRelations[] = [
                          'tagID' => $tagsID,
                          'postID' => $postID,
                          'language' => $langSlug
                        ];
                        $tagsIDs[] = $tagsID;
                    }
                }
            }

            // if post is in the main database
            $insertedTags = (new TagRelation())->setTable($postType->slug.'_tags')->insert($newTagsRelations);
            if($insertedTags) {
                return $tagsIDs;
            }
        }
        return [];
    }
public static function insertTags ( $ selectedTags , $ postID , $ postType ) { if ( count ( $ selectedTags ) ) { $ tagsIDs = [ ] ; $ newTagsRelations = [ ] ; foreach ( $ selectedTags as $ langSlug => $ selectedTagForLanguage ) { if ( $ selectedTagForLanguage ) { foreach ( $ selectedTagForLanguage as $ selectedTag ) { //insert tag if it doesn't exist if ( $ selectedTag [ 'tagID' ] == 0 ) { $ tagSlug = str_slug ( $ selectedTag [ 'title' ] , '-' ) ; $ tagsID = DB :: table ( 'tags' ) -> insertGetId ( [ 'postTypeID' => $ postType [ 'postTypeID' ] , 'createdByUserID' => Auth :: user ( ) -> userID , 'title' => $ selectedTag [ 'title' ] , 'description' => $ selectedTag [ 'description' ] , 'slug' => $ tagSlug , ] ) ; } else { $ tagsID = $ selectedTag [ 'tagID' ] ; } //add new tag relationship $ newTagsRelations [ ] = [ 'tagID' => $ tagsID , 'postID' => $ postID , 'language' => $ langSlug ] ; $ tagsIDs [ ] = $ tagsID ; } } } // if post is in the main database $ insertedTags = ( new TagRelation ( ) ) -> setTable ( $ postType -> slug . '_tags' ) -> insert ( $ newTagsRelations ) ; if ( $ insertedTags ) { return $ tagsIDs ; } } return [ ] ; }
Insert Post tags.

@param array  $selectedTags The list of selected tags
@param int    $postID       ID of the Post
@param object $postType     The slug of post type

@return array  List of inserted media files
Insert Post tags .