public function getMediaFromCustomFields($customFields, ...$slugs)
    {
        $mediaIDs = [];
        foreach($customFields as $fields){
            foreach($fields as $field => $value){
                if(in_array($field, $slugs)) {
                    if(!is_array($value)) {
                        $mediaIDs[] = $value;
                    }else{
                        foreach($value as $subValue){
                            $mediaIDs[] = $subValue;
                        }
                    }
                }
            }
        }

        $media = Media::whereIn("mediaID", $mediaIDs)->get()->keyBy("mediaID")->toArray();

        $object = [];
        if(count($media)) {
            foreach ($customFields as $fields) {
                foreach($fields as $field => $value){
                    if(in_array($field, $slugs)) {
                        if($value && isset($media[$value])) {
                            $tmp = [];
                            if (!is_array($value)) {
                                $fields->$field = new Media($media[$value]);
                            } else {
                                foreach ($value as $subValue) {
                                    $tmp[] = new Media($media[$value]);
                                }
                                $fields->$field = $tmp;
                            }
                        }else{
                            $fields->$field = null;
                        }
                    }
                }
                $object[] = $fields;
            }
        }else{
            $object = $customFields;
        }

        return collect($object);
    }
public function getMediaFromCustomFields($customFields, ...$slugs)
    {
        $mediaIDs = [];
        foreach($customFields as $fields){
            foreach($fields as $field => $value){
                if(in_array($field, $slugs)) {
                    if(!is_array($value)) {
                        $mediaIDs[] = $value;
                    }else{
                        foreach($value as $subValue){
                            $mediaIDs[] = $subValue;
                        }
                    }
                }
            }
        }

        $media = Media::whereIn("mediaID", $mediaIDs)->get()->keyBy("mediaID")->toArray();

        $object = [];
        if(count($media)) {
            foreach ($customFields as $fields) {
                foreach($fields as $field => $value){
                    if(in_array($field, $slugs)) {
                        if($value && isset($media[$value])) {
                            $tmp = [];
                            if (!is_array($value)) {
                                $fields->$field = new Media($media[$value]);
                            } else {
                                foreach ($value as $subValue) {
                                    $tmp[] = new Media($media[$value]);
                                }
                                $fields->$field = $tmp;
                            }
                        }else{
                            $fields->$field = null;
                        }
                    }
                }
                $object[] = $fields;
            }
        }else{
            $object = $customFields;
        }

        return collect($object);
    }
public function getMediaFromCustomFields ( $ customFields , ... $ slugs ) { $ mediaIDs = [ ] ; foreach ( $ customFields as $ fields ) { foreach ( $ fields as $ field => $ value ) { if ( in_array ( $ field , $ slugs ) ) { if ( ! is_array ( $ value ) ) { $ mediaIDs [ ] = $ value ; } else { foreach ( $ value as $ subValue ) { $ mediaIDs [ ] = $ subValue ; } } } } } $ media = Media :: whereIn ( "mediaID" , $ mediaIDs ) -> get ( ) -> keyBy ( "mediaID" ) -> toArray ( ) ; $ object = [ ] ; if ( count ( $ media ) ) { foreach ( $ customFields as $ fields ) { foreach ( $ fields as $ field => $ value ) { if ( in_array ( $ field , $ slugs ) ) { if ( $ value && isset ( $ media [ $ value ] ) ) { $ tmp = [ ] ; if ( ! is_array ( $ value ) ) { $ fields -> $ field = new Media ( $ media [ $ value ] ) ; } else { foreach ( $ value as $ subValue ) { $ tmp [ ] = new Media ( $ media [ $ value ] ) ; } $ fields -> $ field = $ tmp ; } } else { $ fields -> $ field = null ; } } } $ object [ ] = $ fields ; } } else { $ object = $ customFields ; } return collect ( $ object ) ; }
Replaces mediaIDs eith the actuall media object.

@param  array ...$slugs slugs of media in custom field group
@return array
Replaces mediaIDs eith the actuall media object .