在 laravel 5.6 中我的刀片视图有一个未定义的索引问题

沙米拉

我在 laravel 5.6 中的刀片视图有一个未定义的索引问题。我必须运行我的 URL localhost:8000/test 时出现错误Undefined index: Domains 。如果在 url 中传递一些值,如 localhost:8000/test?tld=test&sld=info 它工作正常。请提出任何解决方案。

我的查看页面代码

@foreach($result['Domains']['Domain'] as $key => $value)
      @if($key == 'Name')
      <b>{{$value}}</b> - 
      @endif
      @if($key == "RRPText")
      <b>{{$value}}</b>
      @endif
      @endforeach
      @foreach($result['Domains']['Domain']['Prices'] as $key => $value)
      @if($key == "Registration")
      <b>{{$value}}</b>
      @endif 
      @endforeach

我的控制器代码

$sld = $request['sld'];
        $tld = $request['tld'];
        $response = file_get_contents('https://reseller.enom.com/interface.asp?command=check&sld='. $sld .'&tld='. $tld .'&uid=resellid&pw=resellpw&responsetype=xml&version=2&includeprice=1&includeproperties=1&includeeap=1');  
        $data = simplexml_load_string($response);
        $configdata   = json_encode($data);
        $final_data = json_decode($configdata,true);

我的 API 调用输出

{"interface-response":
{"Domains":
{"Domain":
{"Name":"decksys.info","RRPCode":"210","RRPText":"Domain available","IsPremium":"False","IsPlatinum":"False","IsEAP":"False","Prices":{"Currency":"","Registration":"12.48","Renewal":"12.48","Restore":"250.00","Transfer":"12.48","ExpectedCustomerSuppliedPrice":null}}},"Command":"CHECK","APIType":"API.NET","Language":"eng","ErrCount":"0","ResponseCount":"0","MinPeriod":"1","MaxPeriod":"10","Server":"sjl0vwapi08","Site":"eNom","IsLockable":null,"IsRealTimeTLD":null,"TimeDifference":"+0.00","ExecTime":"0.553","Done":"true","TrackingKey":"a1c38f08-5042-4139-a525-302d987a2b39","RequestDateTime":"5/25/2018 4:23:31 AM","debug":null}}

请提出任何解决方案

卢卡什·伊尔萨克

它说未定义的索引,这意味着数组中不存在$result['Domains']['Domain']$result['Domains']['Domain']['Prices']不存在的

尝试转储您的$results变量,dd($results)在 foreach 之前使用,您会发现没有密钥。

您可以检查isset()该数组中是否存在索引

@if(isset($result['Domains']['Domain'])) 
    @foreach($result['Domains']['Domain'] as $key => $value)
      @if($key == 'Name')
        <b>{{$value}}</b> - 
      @endif
      @if($key == "RRPText")
        <b>{{$value}}</b>
      @endif
    @endforeach
@endif
@if(isset($result['Domains']['Domain']['Prices']))
    @foreach($result['Domains']['Domain']['Prices'] as $key => $value)
      @if($key == "Registration")
        <b>{{$value}}</b>
      @endif 
    @endforeach
@endif

您可以在此处了解有关 PHP 数组的更多信息:https : //www.w3schools.com/php/php_arrays.asp

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章