public static function translateList($items, $languageSlug = '')
    {
        if($items) {
            if(is_a($items, 'Illuminate\Database\Eloquent\Collection')) {
                $translatedItems = $items->map(
                    function ($post) use ($languageSlug) {
                        foreach ($post->getAttributes() as $key => $value) {
                            $post->$key = self::translate($value, $languageSlug);
                        }
                        return $post;
                    }
                );
            } else {
                $translatedItems = $items;
                foreach($items as $key=>$value){
                    $translatedItems->$key = self::translate($value, $languageSlug);
                }
            }

            //if pagination
            if(method_exists($items, "setCollection")) {
                $collection = new Collection($translatedItems);
                return $items->setCollection($collection);
            }

            return $translatedItems;
        }
    }
public static function translateList($items, $languageSlug = '')
    {
        if($items) {
            if(is_a($items, 'Illuminate\Database\Eloquent\Collection')) {
                $translatedItems = $items->map(
                    function ($post) use ($languageSlug) {
                        foreach ($post->getAttributes() as $key => $value) {
                            $post->$key = self::translate($value, $languageSlug);
                        }
                        return $post;
                    }
                );
            } else {
                $translatedItems = $items;
                foreach($items as $key=>$value){
                    $translatedItems->$key = self::translate($value, $languageSlug);
                }
            }

            //if pagination
            if(method_exists($items, "setCollection")) {
                $collection = new Collection($translatedItems);
                return $items->setCollection($collection);
            }

            return $translatedItems;
        }
    }
public static function translateList ( $ items , $ languageSlug = '' ) { if ( $ items ) { if ( is_a ( $ items , 'Illuminate\Database\Eloquent\Collection' ) ) { $ translatedItems = $ items -> map ( function ( $ post ) use ( $ languageSlug ) { foreach ( $ post -> getAttributes ( ) as $ key => $ value ) { $ post -> $ key = self :: translate ( $ value , $ languageSlug ) ; } return $ post ; } ) ; } else { $ translatedItems = $ items ; foreach ( $ items as $ key => $ value ) { $ translatedItems -> $ key = self :: translate ( $ value , $ languageSlug ) ; } } //if pagination if ( method_exists ( $ items , "setCollection" ) ) { $ collection = new Collection ( $ translatedItems ) ; return $ items -> setCollection ( $ collection ) ; } return $ translatedItems ; } }
Translate language fields from a list of objects.

@param object $items        The rows to be translated
@param string $languageSlug slug of language

@return object Returns the list of translated items
Translate language fields from a list of objects .