laravel 5.6 中我的 blade 视图的未定义索引有问题

Have an issue undefined index to my blade view in laravel 5.6

我在 laravel 5.6 中的 blade 视图有一个未定义的索引问题。我必须 运行 我的 URL localhost:8000/测试,同时出现错误 未定义的索引:域 。如果在 [=34 中传递一些值=] 喜欢 localhost:8000/test?tld=test&sld=info 它正在工作 perfectly.please 建议任何解决方案。

我的查看页面代码

@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 变量,在 foreach 之前使用 dd($results),您会发现没有密钥。

您可以使用 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