-2
I need to save the values of the variable $result in a session, follow the code.
class CorreioController extends Controller
{
public function calculate(Request $request)
{
$params = array(
'nCdEmpresa'=>NUll,
'sDsSenha'=>NULL,
'sCepOrigem'=>14942020,
'sCepDestino'=>$_POST['sCepDestino'],
'nVlPeso' =>$_POST['nVlPeso'],
'nCdFormato' =>'1',
'nVlComprimento' =>15,
'nVlAltura' =>15,
'nVlLargura' =>15,
'sCdMaoPropria' => 'n',
'nVlValorDeclarado' => '0',
'sCdAvisoRecebimento' => 'n',
'nCdServico' => $_POST['nCdServico'],
'nVlDiametro' => '0',
'StrRetorno' => 'xml',
'nIndicaCalculo' => '3'
);
$url = ('http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?') . http_build_query($params);
$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$fact = curl_exec($c);
$xml = simplexml_load_string($fact);
$json = json_encode($xml);
$result = json_decode($json, true);
}
}
Yeah, I’d like to reuse those values in a view.
Isn’t it easier for you to just call the view you need with the variable in it? You can do this in the Trolle with: Return view('nameDaView',Compact('variavel1','variavel2','variavelN'));
– Paulo Martins
Note: to convert XML to array just do
$result = (array) $xml
, no need to convert to JSON.– Woss