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

时间:2018-05-25 11:13:36

标签: laravel laravel-5 laravel-4 laravel-5.2

我在laravel 5.6中的刀片视图中遇到了一个未定义索引的问题。我必须运行我的URL localhost:8000 / test,同时收到错误未定义索引:域。如果在url中传递一些值,如localhost:8000 / test?tld = test& sld = info it是完美的工作。请提出任何解决方案。

我的查看页面代码

@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}}

请建议任何解决方案

1 个答案:

答案 0 :(得分:1)

它表示未定义的索引,表示数组中不存在billcrown(grir)$result['Domains']['Domain']的键。

尝试在foreach之前使用$result['Domains']['Domain']['Prices']转储您的$results变量,您会发现没有密钥。

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

isset()

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