Untitled

mail@pastecode.io avatar
unknown
plain_text
6 days ago
2.3 kB
2
Indexable
Never
$data    = $response['data'];
        $getRelation   = $this->repoRelation->get(['endpoint_register_id' => $relay->id]);   
        $relayRelation;
        if(isset($getRelation)){
            foreach($getRelation as $val){
                $relayRelation[$val->relation_references_name]   = $this->repo->find($val->relation_endpoint_register_id);  
            }
            
            if (isset($data->data)) {
                $cleanData;
                if (is_array($data->data) && isset($data->data[0]) && is_object($data->data[0])) {
                    foreach($data->data as $hasKey=>$hasValue){
                        $cleanData[$hasKey]  = $hasValue;
                        if(isset($relayRelation)){
                            foreach($relayRelation as $key=>$val){
                                $newKey = $key.'_rel';
                                $responseRelasi = $this->sendRelayRequestRelation($request, $val, $hasValue->$key);
                                if($responseRelasi != null){
                                    $dataRelation = json_decode($responseRelasi->getBody()->getContents(), true);
                                    $cleanData[$hasKey]->$newKey = $dataRelation['data'];
                                } 
                            }
                        }
                    }

                } elseif (is_object($data->data)) {
                    foreach($data as $hasKey=>$hasValue){
                        $cleanData[$hasKey]  = $hasValue;
                        if(isset($relayRelation)){
                            foreach($relayRelation as $key=>$val){
                                $newKey = $key.'_rel';
                                $responseRelasi = $this->sendRelayRequestRelation($request, $val, $hasValue->$key);
                                if($responseRelasi != null){
                                    $dataRelation = json_decode($responseRelasi->getBody()->getContents(), true);
                                    $cleanData[$hasKey]->$newKey = $dataRelation['data'];
                                }  
                            }
                        }
                    }

                    $cleanData = $cleanData['data'];
                }
            }
Leave a Comment