Php 尝试从laravel中的刀片视图获取非对象的属性

Php 尝试从laravel中的刀片视图获取非对象的属性,php,json,laravel,pagination,Php,Json,Laravel,Pagination,我尝试将分页数据显示到数据库…我的分页数据来自已解码的json…我可以传递到要查看的分页数据,但无法在表中显示 .... 这是我在刀片视图中的错误 正在尝试获取非对象的属性 我的结果分页 LengthAwarePaginator {#4177 ▼ #total: 1 #lastPage: 1 #items: Collection {#4169 ▼ #items: array:1 [▼ "data" => array

我尝试将分页数据显示到数据库…我的分页数据来自已解码的json…我可以传递到要查看的分页数据,但无法在表中显示 .... 这是我在刀片视图中的错误

正在尝试获取非对象的属性

我的结果分页

  LengthAwarePaginator {#4177 ▼
      #total: 1
      #lastPage: 1
      #items: Collection {#4169 ▼
        #items: array:1 [▼
          "data" => array:852 [▼
            0 => {#624 ▶}
            1 => {#623 ▶}
            2 => {#628 ▼
              +"ID": "cust1"
              +"PWD": "W6ph5Mm5Pz8GgiULbPgzG37mj9g="
              +"NICK_NAME": "CUST1"
              +"PWD_INVALID_HIT": "0"
              +"PWD_CREATE_DT": "2019/07/22 15:57:15"
              +"INSTITUTION_ID": "C01"
              +"ACL_ID": "L04"
              +"LOGIN_DT": "2019/07/22 15:57:15"
              +"LOGIN_STS_ID": "N"
              +"STS_ID": "C08"
              +"TYPE_ID": "U00"
              +"UPD_ID": "sufyzasukor"
              +"UPD_DT": "2019/07/22 15:57:15"
              +"EMAIL_ID": "cust1@gmail.com"
              +"PHONE_NO_ID": "0"
              +"HP_ID": "0                        "
              +"CRT_DATE_DELETED": null
              +"irel__com_access_level": {#621 …9}
              +"irel__com_user_types": {#630 …5}
              +"irel__com_status": {#631 …5}
            }
}
  #perPage: "15"
  #currentPage: 1
  #path: "http://localhost/IFICSV3/public/configuration/comuserprofiles"
  #query: []
  #fragment: null
  #pageName: "page"
  +onEachSide: 3
  #options: array:2 [▶]
}
我的控制器

public function index()
    {


        $response =  $this->client->get('getUserIndex')->getBody();
         $content = json_decode($response->getContents());



         $total = count($content) ;
         $collection = new \Illuminate\Support\Collection($content);
         $paginationRecord = CollectionPaginate::paginate($collection, $total, '15');



         return view('configuration.comuserprofiles.ComUserProfilesList', ['paginationRecord' => $paginationRecord]);

}
我要显示的刀片表

    <tbody>
             @foreach($paginationRecord as $i=>$user)
              @php
              $currentRecordno = 1;

              @endphp  


              <tr>

       <td>{{ $user->ID }}</td>
       <td>{{ $user->NICK_NAME }}</td>
       <td>{{ $user->PWD_INVALID_HIT }}</td>


        </tr>
@endforeach 

如何在表中显示数据

您正试图将数组作为对象访问。这就是错误的原因。试试这个

<tbody>
             @foreach($paginationRecord as $i=>$user)
              @php
                 $currentRecordno = 1;
              @endphp  

              <tr>
                <td>{{ $user['ID'] }}</td>
                <td>{{ $user['NICK_NAME'] }}</td>
                <td>{{ $user['PWD_INVALID_HIT'] }}</td>
             </tr>
             @endforeach 

@foreach($i=>$user的分页记录)
@php
$currentRecordno=1;
@endphp
{{$user['ID']}
{{$user['NICK_NAME']}
{{$user['PWD_INVALID_HIT']}
@endforeach

我认为这是因为$user变量中有一个集合。您需要循环使用$user变量,如下所示:

<tbody>
@foreach($paginationRecord as $i=>$user)
   @php
     $currentRecordno = 1;
   @endphp  
   @foreach($user as $i => $u)
   <tr>
       <td>{{ $u['ID'] }}</td>
       <td>{{ $u['NICK_NAME'] }}</td>
       <td>{{ $u['PWD_INVALID_HIT'] }}</td>
   </tr>
   @endforeach
@endforeach 
foreach循环中的$i应表示索引或$currentRecordno。但如果你有充分的理由,那就坚持下去。

为了可读性:

但实际上,我可能不会做额外的foreach循环

我认为您的控制器方法应该更像:

public function index()
{
        $response =  $this->client->get('getUserIndex')->getBody();
         $content = json_decode($response->getContents());
         $paginationRecord = CollectionPaginate::paginate($content['data'], count($content), '15');

         return view('configuration.comuserprofiles.ComUserProfilesList', ['paginationRecord' => $paginationRecord]);

}
实际上,您的刀片需要更改为:

<tbody>
@foreach($paginationRecord as $i=>$user)
   @php
     $currentRecordno = 1;
   @endphp  
   <tr>
       <td>{{ $user['ID'] }}</td>
       <td>{{ $user['NICK_NAME'] }}</td>
       <td>{{ $user['PWD_INVALID_HIT'] }}</td>
   </tr>
@endforeach 

@foreach($i=>$user的分页记录)
@php
$currentRecordno=1;
@endphp
{{$user['ID']}
{{$user['NICK_NAME']}
{{$user['PWD_INVALID_HIT']}
@endforeach

什么是
CollectionPaginate
?我不认识。@Waterlomatt它来自App\Helpers\CollectionPaginate;尝试一个简单的方法:-
$users=DB::table('users')->paginate(15)了解更多信息:-嗨…我已经尝试过了,但它返回了错误,这是未定义的索引:ids它告诉你这里的未定义索引是什么吗?它说未定义的IDI只是编辑我的问题addind dd($user)…也许你可以帮我如何显示你有嵌套数组。通过
$user
循环将解决此问题
public function index()
{
        $response =  $this->client->get('getUserIndex')->getBody();
         $content = json_decode($response->getContents());
         $paginationRecord = CollectionPaginate::paginate($content['data'], count($content), '15');

         return view('configuration.comuserprofiles.ComUserProfilesList', ['paginationRecord' => $paginationRecord]);

}
<tbody>
@foreach($paginationRecord as $i=>$user)
   @php
     $currentRecordno = 1;
   @endphp  
   <tr>
       <td>{{ $user['ID'] }}</td>
       <td>{{ $user['NICK_NAME'] }}</td>
       <td>{{ $user['PWD_INVALID_HIT'] }}</td>
   </tr>
@endforeach