Home » Php » php – How do i paginate JSON response in controller laravel with guzzle

php – How do i paginate JSON response in controller laravel with guzzle

Posted by: admin February 25, 2020 Leave a comment

Questions:

i try to paginate my JSON response but i dont know how …here is my code with example of response ….i already have my paginate blade and yielded into my view blade……How do i paginate those JSON response based on how i create the paginate page?


 "data": [
 {
            "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_DT": "2019/07/22 15:57:15",
            "EMAIL_ID": "[email protected]",
            "PHONE_NO_ID": "0",
            "HP_ID": "0                        ",
            "CRT_DATE_DELETED": null,

        },

my controller

 private $client;

    public function __construct(){


        $this->client = new Client(['base_uri' => 'http://172.19.5.6/api/configuration/']);

    }

 public function index()
    {

        $response =  $this->client->get('getUserIndex')->getBody();
        $content = json_decode($response->getContents()); // my response json that i want to paginate 



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

    }

my view


@extends('master')

@include('pagination')
@section('content')

 @foreach($content as $i=>$user)
                        @php
                            $currentRecordno = 1;
                        @endphp
                        <tr>
                            <td>{{ $currentRecordno + $i }}</td>
                            <td>{{ $user->ID }}</td>
                            <td>{{ $user->NICK_NAME }}</td>
                            <td>{{ $user->PWD_INVALID_HIT }}</td>

            <footer class="panel-footer">
               @yield('pagination')
            </footer>

@endsection


my paginate view

@section('pagination')
<div class="row row-pagination">
    <div class="col-sm-6 text-left">
        <small class="text-muted inline m-t-sm m-b-sm"><font color="#00000f">{{ $paginationRecord->total() }} record/s found </font></small> 
    </div>
    <div class="col-md-6 text-right text-center-xs">
        <ul>
            {{ $paginationRecord->links() }}
        </ul>
    </div>
</div>  
@endsection

i expect that all my json data display in table view by pagination

How to&Answers: