0

when I use dd($arr) in controller the decoded json data gets printed correctly. How can I pass this decoded json data into my view?

Controller Code

public function test()
{
    // $sld = $request['sld'];
    // $tld = $request['tld'];
    $response = Curl::to('https://reseller.enom.com/interface.asp?command=check&sld=decksys&tld=info&responsetype=xml&uid=resellid&pw=resellpw')
        ->get();

   //check if we are getting a response

 $xml = simplexml_load_string($response);
 $json   = json_encode($xml);

 $arr = json_decode($json, true);
 dd($arr);
 return view('clientlayout.main.test', compact('arr'));

}

Blade File:

`{{ $arr }}` 

My Route file is given below:

 Route::get('/test','EnomController@test');

How to solve this error?

htmlspecialchars() expects parameter 1 to be string, array given

3
  • what is a output shown in dd($arr) Commented May 5, 2018 at 6:54
  • This is the output of dd($arr) array:19 [▼ "Command" => "CHECK" "APIType" => "API.NET" "Language" => "eng" "ErrCount" => "1" "errors" => array:1 [▶] "ResponseCount" => "1" "responses" => array:1 [▶] "MinPeriod" => "1" "MaxPeriod" => "10" "Server" => "sjl0vwapi16" "Site" => "eNom" "IsLockable" => "True" "IsRealTimeTLD" => "True" "TimeDifference" => "+7.00" "ExecTime" => "0.036" "Done" => "true" "TrackingKey" => "999b66f5-5485-4dfa-bb9e-8424d4d0e9ae" "RequestDateTime" => "5/4/2018 11:56:38 PM" "debug" => [] ] Commented May 5, 2018 at 6:57
  • ok I'll update my answer Commented May 5, 2018 at 7:16

2 Answers 2

0
return view('clientlayout.main.test', compact('arr'))->with('arr', $arr); 

and your view: {{ $data['obj'] }} will work.

Sign up to request clarification or add additional context in comments.

Comments

0

The answer for this error is already available on stack, you are accessing those objects which are empty or blank here is a link of solution: htmlspecialchars expects parameter 1 to be string

ok in controller use curl like:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
            "https://reseller.enom.com/interface.asp?command=check&sld=decksys&tld=info&responsetype=json&uid=resellid&pw=resellpw");
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate");
$arr  = json_decode(curl_exec($ch), true);
curl_close($ch);

then return data to view, use foreach loop in view like:

@foreach($arr as $item)
    {{$item['Command']}}
    {{$item['APIType']}}
@endforeach

and want to check before print use isset:

@if(isset($item['Command']))
    {{$item['Command']}}
@endif

Hope this help

2 Comments

This is ok. But the issue is, the data from the above json is not getting displayed / printed in my view file. When I use {{$item['Command']}} I'm getting illegal string offset Command.
API is returning xml and after conversion to json it is given json validation error. I recommended to use responseType=json in API like:[reseller.enom.com/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.