original_string: public function savePostMetaToDatabase($postmeta, $postTypeModel, $post, $request = [], $customFieldKey = '')
  	{
  		// Presetting a empty array so we can append pivot values to the sync function.
  		$pivotValue = [];
  		$object = [];
  
  		$postmeta = $this->removeUnrequiredMetas($postmeta, $postTypeModel);
  
  		if(!empty($customFieldKey)){
  			if($request->hasFile('file')){
  				$postmeta[$customFieldKey] = '';
  			}
  		}
  
  		// Saving the meta values to the database.
  		foreach($postmeta as $key => $value){
  
  			$customFieldObject = $this->getCustomFieldObject($postTypeModel, $key);
  			if($customFieldObject){
  				if(array_key_exists('saveable', $customFieldObject)){
  					if($customFieldObject['saveable'] === false){
  						continue;
  					}
  				}
  			}
  
  			// Lets validate if there is a mutator for this value.
  			$value = $this->saveMutator($postTypeModel, $key, $value, $post, $postmeta, $request);
  
  			// If the custom field does not exist, we may not save it.
  			$customFieldObject = $this->getCustomFieldObject($postTypeModel, $key);
  			if(!is_array($customFieldObject)){
  				continue;
  			}
  
  			$type = 'simple';
  			if(array_key_exists('type', $customFieldObject)){
  				$type = $customFieldObject['type'];
  			}
  			switch($type){
  				case 'taxonomy':
  
  					if(!array_key_exists('post_type', $customFieldObject) && empty($customFieldObject['post_type'])){
  						continue;
  					}
  
  					$customfieldPostTypes = $this->getPostTypeIdentifiers($customFieldObject['post_type']);
  
  					if(!is_array($customfieldPostTypes)){
  						continue;
  					}
  
  					if(!is_array($value)){
  						$value = json_decode($value, true);
  					}
  
  					// Yes, double.
  					if(!is_array($value)){
  						continue;
  					}
  
  					foreach($value as $valueKey => $valueItem){
  
  						$where = [];
  
  						if($postTypeModel->userCanOnlySeeHisOwnPosts){
  							$where[] = ['post_author', '=', Auth::user()->id];
  						}
  
  						$where[] = ['id', '=', $valueItem];
  
  						// For each post id give, we need to query the database and validate if this
  						// taxonomie of the connect post does exist and we got permission to it.
  						$taxonomyPost = NikuPosts::where($where)
  							->whereIn('post_type', $customfieldPostTypes)
  							->first();
  
  						// If there is a taxonomy result, we can safely add it to the pivot.
  						if($taxonomyPost) {
  							$pivotValue[$valueItem] = ['taxonomy' => $key];
  						}
  
  					}
  
  					$post->taxonomies()->sync($pivotValue);
  
  				break;
  				default:
  
  					$object[$key] = $value;
  
  				break;
  			}
  
  		}
  
  		$post->saveMetas($object);
  
  		return $post;
  	}
code: public function savePostMetaToDatabase($postmeta, $postTypeModel, $post, $request = [], $customFieldKey = '')
  	{
  		// Presetting a empty array so we can append pivot values to the sync function.
  		$pivotValue = [];
  		$object = [];
  
  		$postmeta = $this->removeUnrequiredMetas($postmeta, $postTypeModel);
  
  		if(!empty($customFieldKey)){
  			if($request->hasFile('file')){
  				$postmeta[$customFieldKey] = '';
  			}
  		}
  
  		// Saving the meta values to the database.
  		foreach($postmeta as $key => $value){
  
  			$customFieldObject = $this->getCustomFieldObject($postTypeModel, $key);
  			if($customFieldObject){
  				if(array_key_exists('saveable', $customFieldObject)){
  					if($customFieldObject['saveable'] === false){
  						continue;
  					}
  				}
  			}
  
  			// Lets validate if there is a mutator for this value.
  			$value = $this->saveMutator($postTypeModel, $key, $value, $post, $postmeta, $request);
  
  			// If the custom field does not exist, we may not save it.
  			$customFieldObject = $this->getCustomFieldObject($postTypeModel, $key);
  			if(!is_array($customFieldObject)){
  				continue;
  			}
  
  			$type = 'simple';
  			if(array_key_exists('type', $customFieldObject)){
  				$type = $customFieldObject['type'];
  			}
  			switch($type){
  				case 'taxonomy':
  
  					if(!array_key_exists('post_type', $customFieldObject) && empty($customFieldObject['post_type'])){
  						continue;
  					}
  
  					$customfieldPostTypes = $this->getPostTypeIdentifiers($customFieldObject['post_type']);
  
  					if(!is_array($customfieldPostTypes)){
  						continue;
  					}
  
  					if(!is_array($value)){
  						$value = json_decode($value, true);
  					}
  
  					// Yes, double.
  					if(!is_array($value)){
  						continue;
  					}
  
  					foreach($value as $valueKey => $valueItem){
  
  						$where = [];
  
  						if($postTypeModel->userCanOnlySeeHisOwnPosts){
  							$where[] = ['post_author', '=', Auth::user()->id];
  						}
  
  						$where[] = ['id', '=', $valueItem];
  
  						// For each post id give, we need to query the database and validate if this
  						// taxonomie of the connect post does exist and we got permission to it.
  						$taxonomyPost = NikuPosts::where($where)
  							->whereIn('post_type', $customfieldPostTypes)
  							->first();
  
  						// If there is a taxonomy result, we can safely add it to the pivot.
  						if($taxonomyPost) {
  							$pivotValue[$valueItem] = ['taxonomy' => $key];
  						}
  
  					}
  
  					$post->taxonomies()->sync($pivotValue);
  
  				break;
  				default:
  
  					$object[$key] = $value;
  
  				break;
  			}
  
  		}
  
  		$post->saveMetas($object);
  
  		return $post;
  	}
code_tokens: public function savePostMetaToDatabase ( $ postmeta , $ postTypeModel , $ post , $ request = [ ] , $ customFieldKey = '' ) { // Presetting a empty array so we can append pivot values to the sync function. $ pivotValue = [ ] ; $ object = [ ] ; $ postmeta = $ this -> removeUnrequiredMetas ( $ postmeta , $ postTypeModel ) ; if ( ! empty ( $ customFieldKey ) ) { if ( $ request -> hasFile ( 'file' ) ) { $ postmeta [ $ customFieldKey ] = '' ; } } // Saving the meta values to the database. foreach ( $ postmeta as $ key => $ value ) { $ customFieldObject = $ this -> getCustomFieldObject ( $ postTypeModel , $ key ) ; if ( $ customFieldObject ) { if ( array_key_exists ( 'saveable' , $ customFieldObject ) ) { if ( $ customFieldObject [ 'saveable' ] === false ) { continue ; } } } // Lets validate if there is a mutator for this value. $ value = $ this -> saveMutator ( $ postTypeModel , $ key , $ value , $ post , $ postmeta , $ request ) ; // If the custom field does not exist, we may not save it. $ customFieldObject = $ this -> getCustomFieldObject ( $ postTypeModel , $ key ) ; if ( ! is_array ( $ customFieldObject ) ) { continue ; } $ type = 'simple' ; if ( array_key_exists ( 'type' , $ customFieldObject ) ) { $ type = $ customFieldObject [ 'type' ] ; } switch ( $ type ) { case 'taxonomy' : if ( ! array_key_exists ( 'post_type' , $ customFieldObject ) && empty ( $ customFieldObject [ 'post_type' ] ) ) { continue ; } $ customfieldPostTypes = $ this -> getPostTypeIdentifiers ( $ customFieldObject [ 'post_type' ] ) ; if ( ! is_array ( $ customfieldPostTypes ) ) { continue ; } if ( ! is_array ( $ value ) ) { $ value = json_decode ( $ value , true ) ; } // Yes, double. if ( ! is_array ( $ value ) ) { continue ; } foreach ( $ value as $ valueKey => $ valueItem ) { $ where = [ ] ; if ( $ postTypeModel -> userCanOnlySeeHisOwnPosts ) { $ where [ ] = [ 'post_author' , '=' , Auth :: user ( ) -> id ] ; } $ where [ ] = [ 'id' , '=' , $ valueItem ] ; // For each post id give, we need to query the database and validate if this // taxonomie of the connect post does exist and we got permission to it. $ taxonomyPost = NikuPosts :: where ( $ where ) -> whereIn ( 'post_type' , $ customfieldPostTypes ) -> first ( ) ; // If there is a taxonomy result, we can safely add it to the pivot. if ( $ taxonomyPost ) { $ pivotValue [ $ valueItem ] = [ 'taxonomy' => $ key ] ; } } $ post -> taxonomies ( ) -> sync ( $ pivotValue ) ; break ; default : $ object [ $ key ] = $ value ; break ; } } $ post -> saveMetas ( $ object ) ; return $ post ; }
docstring: Saving the post meta to the database
docstring_tokens: Saving the post meta to the database