public function mergeWithRinvex($natural, $rinvex, $translation, $suffix = '_rinvex')
    {
        $defaultToRinvex = coollect([
            'currency',
            'languages',
            'dialling',
        ]);

        $merge = coollect([
            'geo',
            'translations',
            'flag',
        ]);

        $natural = $this->fillRinvexFields($natural);

        if ($rinvex->isEmpty()) {
            return $natural;
        }

        $rinvex['translations'] = $translation;

        $rinvex['flag'] = ['emoji' => $rinvex['extra']['emoji']];

        $result = [];

        foreach ($rinvex->keys()->merge($natural->keys()) as $key) {
            $naturalValue = arrayable($var = $natural->get($key)) ? $var->sortByKeysRecursive()->toArray() : $var;

            $rinvexValue = arrayable($var = $rinvex->get($key)) ? $var->sortByKeysRecursive()->toArray() : $var;

            if (is_null($naturalValue) || is_null($rinvexValue)) {
                $result[$key] = $rinvexValue ?: $naturalValue;

                continue;
            }

            if ($rinvexValue !== $naturalValue && $merge->contains($key)) {
                $result[$key] = coollect($naturalValue)->overwrite($rinvexValue);

                continue;
            }

            if ($rinvexValue !== $naturalValue && ! $defaultToRinvex->contains($key)) {
                $result[$key.$suffix] = $rinvexValue; // Natural Earth Vector
            }

            $result[$key] = $defaultToRinvex->contains($key)
                ? $rinvexValue
                : $naturalValue; // Natural Earth Vector
        }

        return coollect($result)->sortBy(function ($value, $key) {
            return $key;
        });
    }
public function mergeWithRinvex($natural, $rinvex, $translation, $suffix = '_rinvex')
    {
        $defaultToRinvex = coollect([
            'currency',
            'languages',
            'dialling',
        ]);

        $merge = coollect([
            'geo',
            'translations',
            'flag',
        ]);

        $natural = $this->fillRinvexFields($natural);

        if ($rinvex->isEmpty()) {
            return $natural;
        }

        $rinvex['translations'] = $translation;

        $rinvex['flag'] = ['emoji' => $rinvex['extra']['emoji']];

        $result = [];

        foreach ($rinvex->keys()->merge($natural->keys()) as $key) {
            $naturalValue = arrayable($var = $natural->get($key)) ? $var->sortByKeysRecursive()->toArray() : $var;

            $rinvexValue = arrayable($var = $rinvex->get($key)) ? $var->sortByKeysRecursive()->toArray() : $var;

            if (is_null($naturalValue) || is_null($rinvexValue)) {
                $result[$key] = $rinvexValue ?: $naturalValue;

                continue;
            }

            if ($rinvexValue !== $naturalValue && $merge->contains($key)) {
                $result[$key] = coollect($naturalValue)->overwrite($rinvexValue);

                continue;
            }

            if ($rinvexValue !== $naturalValue && ! $defaultToRinvex->contains($key)) {
                $result[$key.$suffix] = $rinvexValue; // Natural Earth Vector
            }

            $result[$key] = $defaultToRinvex->contains($key)
                ? $rinvexValue
                : $naturalValue; // Natural Earth Vector
        }

        return coollect($result)->sortBy(function ($value, $key) {
            return $key;
        });
    }
public function mergeWithRinvex ( $ natural , $ rinvex , $ translation , $ suffix = '_rinvex' ) { $ defaultToRinvex = coollect ( [ 'currency' , 'languages' , 'dialling' , ] ) ; $ merge = coollect ( [ 'geo' , 'translations' , 'flag' , ] ) ; $ natural = $ this -> fillRinvexFields ( $ natural ) ; if ( $ rinvex -> isEmpty ( ) ) { return $ natural ; } $ rinvex [ 'translations' ] = $ translation ; $ rinvex [ 'flag' ] = [ 'emoji' => $ rinvex [ 'extra' ] [ 'emoji' ] ] ; $ result = [ ] ; foreach ( $ rinvex -> keys ( ) -> merge ( $ natural -> keys ( ) ) as $ key ) { $ naturalValue = arrayable ( $ var = $ natural -> get ( $ key ) ) ? $ var -> sortByKeysRecursive ( ) -> toArray ( ) : $ var ; $ rinvexValue = arrayable ( $ var = $ rinvex -> get ( $ key ) ) ? $ var -> sortByKeysRecursive ( ) -> toArray ( ) : $ var ; if ( is_null ( $ naturalValue ) || is_null ( $ rinvexValue ) ) { $ result [ $ key ] = $ rinvexValue ? : $ naturalValue ; continue ; } if ( $ rinvexValue !== $ naturalValue && $ merge -> contains ( $ key ) ) { $ result [ $ key ] = coollect ( $ naturalValue ) -> overwrite ( $ rinvexValue ) ; continue ; } if ( $ rinvexValue !== $ naturalValue && ! $ defaultToRinvex -> contains ( $ key ) ) { $ result [ $ key . $ suffix ] = $ rinvexValue ; // Natural Earth Vector } $ result [ $ key ] = $ defaultToRinvex -> contains ( $ key ) ? $ rinvexValue : $ naturalValue ; // Natural Earth Vector } return coollect ( $ result ) -> sortBy ( function ( $ value , $ key ) { return $ key ; } ) ; }
Merge country data with Rinvex data.

@param Coollection $natural
@param Coollection $rinvex
@param $translation
@param string $suffix
@return mixed|\PragmaRX\Coollection\Package\Coollection
Merge country data with Rinvex data .