【问题标题】:How do i display pagination data to table in Laravel如何在 Laravel 中将分页数据显示到表格中
【发布时间】:2020-06-03 10:49:37
【问题描述】:

我尝试将指定的分页数据显示到表...我的分页数据包含已在控制器中解码的 json...我想在表中显示 NICK_NAME

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', compact('paginationRecord'));
}

这是我的分页记录

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"  //i want display this
          +"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 [▶]
}

我如何从这里写

<tbody>
          @foreach($paginationRecord as $i=>$user)
                   <td>$user ??<td>      
          @endforeach
</tbody>

如何从 LengthAwarePaginator 访问和显示数据?抱歉,如果我的解释不清楚,因为这对我来说是新事物

【问题讨论】:

    标签: php json laravel pagination


    【解决方案1】:

    调用分页方法时,会收到Illuminate\Pagination\LengthAwarePaginator的实例

    因此,一旦您检索到结果,您就可以显示结果并使用 Blade 呈现页面链接:

    <div class="container">
        @foreach ($users as $user)
            {{ $user->name }}
        @endforeach
    </div>
    
    {{ $users->links() }}
    

    links 方法将呈现指向结果集中其余页面的链接。这些链接中的每一个都已经包含正确的页面查询字符串变量。

    来源:https://laravel.com/docs/5.8/pagination

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-31
      • 1970-01-01
      • 2014-02-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多