【问题标题】:how to pass a value from repository to the controller in laravel如何将值从存储库传递到laravel中的控制器
【发布时间】:2020-03-02 18:03:10
【问题描述】:

SmartpaySPaymentRepository.php

我是 laravel 的新手。我想将 SmartpaySPaymentRepository.php sendPaymentToSmartpaySForPaymentToken 函数中的这个值 ($url->nodeValue) 传递给 SmartPaySController.php getQuotePayment($quoteId) 函数有人可以帮我这样做吗?

public function sendPaymentToSmartpaySForPaymentToken($xml, $authToken, $transactionId, $doPrepareUrl)
        {
            $fields = array(
                'authToken' => $authToken,
                '&requestXML' => $xml,
            );

            $fields_string = $xml;
            foreach ($fields as $key => $value) {
                $fields_string .= $key . '=' . $value . '&';

            }
            rtrim($fields_string, '&');

            //open connection
            $ch = curl_init($doPrepareUrl);


            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POST, 2);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
            $response_from_smartpays = curl_exec($ch);

            curl_close($ch);


                $testString = $response_from_smartpays;//xml string
                $dom = new \DOMDocument();
                $dom->formatOutput = TRUE;
                $dom->preserveWhiteSpace = FALSE;
                $dom->loadXml($testString);

                $result = ($dom->getElementsByTagName('redirectURL'));
                foreach ($result as $url){

                 return ($url->nodeValue);//want to passe this value to controller


                }
        }

SmartPaySController.php

public function getQuotePayment($quoteId)
    {
        $quote = $this->quoteRepo->getQuoteById($quoteId);
        if($quote) {
            $totalPrice = $quote->total_price;
            if ($quote->amended_policy) {
                $totalPrice = $quote->amend_price;

            }
                dd($url->nodeValue);//want to use $url->nodeValue here

            $currency = CURRENCY_TYPE;
            return $this->processSmartpaySPayment(PAYMENT_TYPE_QUOTE, $totalPrice, $currency, $quote->customer_id, $quoteId);
        }else {
            abort(404);
        }

    }

【问题讨论】:

    标签: php html mysql laravel web-deployment


    【解决方案1】:

    您可以将它们作为存储库中的数组返回

    $resultReturn = []
    
    foreach ($result as $url){
        $resultReturn[] =  ($url->nodeValue);//want to passe this value to controller
    }
    
    return $resultReturn; // pass the array contiling all rsults in the loop
    

    在控制器中

    $currency = CURRENCY_TYPE;
    $results =  $this->processSmartpaySPayment(PAYMENT_TYPE_QUOTE, $totalPrice, $currency, $quote->customer_id, $quoteId);
    
    dd($results); //array of $url->nodeValue here
    
    return $results;
    
    

    【讨论】:

      猜你喜欢
      • 2011-12-22
      • 1970-01-01
      • 2013-12-09
      • 1970-01-01
      • 1970-01-01
      • 2016-04-16
      • 2020-06-01
      • 2015-07-04
      • 1970-01-01
      相关资源
      最近更新 更多