Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我能';t正确打印同一表格中2个rest api的值_Php_Laravel_Api - Fatal编程技术网

Php 我能';t正确打印同一表格中2个rest api的值

Php 我能';t正确打印同一表格中2个rest api的值,php,laravel,api,Php,Laravel,Api,我试图在同一个表中打印来自2个rest api的数组。第一个工作正常,但第二个数组无法正确打印。有人知道如何解决这个问题吗 RESTAPI json RESTAPI json 拉威尔控制器 //Listing clients from java application public function getDevices(){ $path=file_get_contents("C:\Users\Desktop\projekt1.2.2017\edit_path\edit_url.txt"

我试图在同一个表中打印来自2个rest api的数组。第一个工作正常,但第二个数组无法正确打印。有人知道如何解决这个问题吗

RESTAPI json

RESTAPI json

拉威尔控制器

//Listing clients from java application 
public function getDevices(){
$path=file_get_contents("C:\Users\Desktop\projekt1.2.2017\edit_path\edit_url.txt");

   try{
    $device= new Client();

    $answer= $client->request('GET', $path.'devices');
    $body = $answer->getBody();
    $status = 'true';
    $message = 'Data found!';
    $result= json_decode($body);
        $id_array = array();
    foreach ($result as $item) {
        // Add each id value in your array
        $id_array[]= $item->clientId;
    }

$b = array();
foreach($id_array as $my_id) {
 $answer2 = $device->request('GET', $path. 'devices/deviceAvailability/' . $my_id );
 $b[] = $answer2 ->getBody();


}

return view('devices.home', ['devices' => $result, 'status'=> $b]);
    // is thrown for 400 level errors 
}catch(ClientException $ce){
    $status = 'false';
    $message = $ce->getMessage();
    $result= [];
    //In the event of a networking error (connection timeout, DNS errors, etc.)
}catch(RequestException $re){
   $status = 'false';
   $message = $re->getMessage();
   $result= [];
}//If some error occurs
catch(Exception $e){
   $this->status = 'false';
   $this->message = $e->getMessage();
   $result= [];
}
 Session::flash('error', 'Devices list is empty, no connection !');
return view('devices.home', ['status'=>$status,'message'=>$message,'devices'=>$result]);
}
blade php中的表

<div class="table-responsive">

        <table class="table  new_table table-striped" style="text-align: center;">

            <thead>
                <tr>

                    <th>Device Name</th>
                    <th>Device Address </th>
                    <th>Device Socket </th>
                    <th>Device Frequency Collection </th>
                    <th>Device Frequency Upload </th>
                    <th>Server Name</th>
                    <th>Server Address</th>
                    <th>Server Socket</th>
                    <th>Device avialibilty</th>
                    <th>Device Profile</th>
             @if(!Sentinel::viewer())
                 @if(Sentinel::inRole('admin'))          
                    <th>Change bouth Device Freqs</th>
                    <th>Change Device Socket and Address/th> 
                    <th>Remove Device</th>


                @endif
            @endif                      
                </tr>
            </thead>

           <tbody>

                @forelse ($devices as $device)


               <tr>

                    <td>{{ $device->deviceAllias }}</td>
                    <td>{{ $device->deviceIp }}</td>
                    <td>{{ $device->devicePort }}</td>
                    <td>{{ $device->data_Collection_Frequency }}</td>
                    <td>{{ $device->dataUpload_Frequency }}</td>
                    <td>{{ $device->serverAllias }}</td>
                    <td>{{ $device->serverIp }}</td>
                    <td>{{ $device->serverPort }}</td>
                    <td> @foreach($status as $stat)  
                   @if( $stat == "true")
                             <i class="fa fa-check-circle" style="font-size:18px;color:green">Online</i>
                        @else

                              <i class="fa fa-remove" style="font-size:18px;color:red">Offline</i>     

                  @endif 

               @endforeach</td>





         <td> 
             <a href="{{route('device.profile',  ['deviceID ' =>  $device-> deviceID])}}" class="btn btn-info pull-left" style="margin-right: 3px;">Profile</a>
         </td> 


  @if(!Sentinel::guest())
      @if(Sentinel::inRole('admin'))

     <td> 

       <a href="{{route('device.change',  ['deviceID' =>  $device-> deviceID])}}" class="btn btn-info pull-left" style="margin-right: 3px;">Frequencies Edit</a>
                 </td>  

            <td> 
       <a href="{{route('device.change.port',  ['deviceID' =>  $device-> deviceID])}}" class="btn btn-info pull-left" style="margin-right: 3px;">Port Change</a>
                 </td> 

                     <td>  
            <a href="{{route('device.delete',  ['deviceID' =>  $device-> deviceID])}}" class="btn btn-danger pull-left" style="margin-right: 3px;">Remove</a>

                 </td> 
          @endif
   @endif    

                @empty
              @if(session('error')) 
                <div class="alert alert-danger">
                    {{ session('error') }}  
                    <p>Status:  {{$status}} </p>   
                      <p> Failure explanation:  {{ $message}} </p> 
                </div>
            @endif


        @endforelse

                       </tr> 





            </tbody>





        </table>
    </div>
  @if(!Sentinel::guest())
      @if(Sentinel::inRole('admin'))  
          @if(count($clients) !== 0)


            <a href="{{ route('device.new') }}" class="btn btn-success pull-right">Register a new Device</a>

           @endif
      @endif
  @endif 
  <h3>Clients Activity</h3>
       <table id="tablica" class="table table-bordered table-striped" style="width: 100px">



            <tbody>
                      @foreach ($devices $device)    
                       <tr>
                         <td>{{ $device->deviceAllias }}</td>
                       </tr> 

                     @endforeach



            </tbody>
        </table>

设备名
设备地址
设备插座
设备频率采集
设备频率上传
服务器名
服务器地址
服务器套接字
设备安全性
设备配置文件
@如果(!Sentinel::viewer())
@if(Sentinel::inRole('admin'))
更改边界设备频率
更改设备插座和地址/th>
移除设备
@恩迪夫
@恩迪夫
@forelse($devices as$device)
{{$device->deviceAllias}
{{$device->deviceIp}
{{$device->devicePort}
{{$device->data\u Collection\u Frequency}
{{$device->dataUpload\u Frequency}
{{$device->serverAllias}
{{$device->serverIp}
{{$device->serverPort}
@foreach($stat状态)
@如果($stat==“true”)
在线 的
@否则
离线
@恩迪夫
@endforeach
@如果(!Sentinel::guest())
@if(Sentinel::inRole('admin'))
@恩迪夫
@恩迪夫
@空的
@if(会话('error'))
{{session('error')}
状态:{{$Status}}

失败解释:{{$message}}

@恩迪夫 @endforelse @如果(!Sentinel::guest()) @if(Sentinel::inRole('admin')) @如果(计数($clients)!==0) @恩迪夫 @恩迪夫 @恩迪夫 客户活动 @foreach($devices$device) {{$device->deviceAllias} @endforeach
尝试更改此行:

$a[] = $response2->getBody();
致:


您是否在问为什么第二个数组图片中的内容看起来不像第一个数组中的内容?也许修改$a[]=json_解码($response2->getBody())?是的,我怎样做修改?
$a[] = json_decode($response2->getBody());