SERT12's avatar

how to set pagination with offset and limit. then how to show on blade. my code like that;

public function shipment(Request $request,$offset=0,$limit=0)
    {   
        $rdf = $request->input('date-from');
        $rdt = $request->input('date-to');

        if($rdf == "" && $rdt == "")
        {
            return redirect()->route('gh');
        }
        $date_from = ( $rdf == "" ) ? getLastSevenThDay()  : date_format(date_create($rdf),"Y-m-d");
        $date_to = ( $rdt == "" ) ? getNextSevenThDay() : date_format(date_create($rdt),"Y-m-d");

        $ghl = $this->apiController->search_with_date_range($date_from,$date_to,20,30);
        
        if($ghl == 'Fail')
        {
            return redirect()->action('LogoutController@instant_logout');
        }
        return view('pages.gh', compact('ghl','rdf','rdt'));
0 likes
6 replies
SilenceBringer's avatar

@sert12 do you think we know whaat $this->apiController->search_with_date_range do? What's the result of this method? LengthAwarePaginator instance? Some kind of array?

1 like
crystalmixz7's avatar

@SilenceBringer from apicontroller

public function search_with_date_range($date_from,$date_to, $offset=0,$limit=0)
    {
        $customer = Customer::find(Auth::id());

        //SEARCH WITH DATE RANGE
        $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_URL => $this->api_url.'/api/bill',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'GET',
            CURLOPT_POSTFIELDS => array(
                'login' => Auth::user()->login,
                'password' => Crypt::decrypt(Auth::user()->login_api),
                'db' => 'digital',
                'domain' => '[(\'sender_id\',\'=\','.$customer->customer_detail->user_id.'),(\'bill_date\', \'>=\', \''.$date_from.'\'),(\'bill_date\', \'<=\', \''.$date_to.'\')]',
                'fields' => '[\'id\',\'name\',\'to_city_id\',\'order_ref\',\'cod\',\'weight\',\'service_charges\',\'receiver_id\',\'bill_date\',\'state\']',
                'offset'=> $offset,
                'limit'=>$limit,
                'order' => 'id desc'
            ),  
            CURLOPT_HTTPHEADER => array(
                
                'access-token: '.Auth::user()->access_token,
                'Cookie: session_id=c4c9a042b0910f91050ee7b349319a5deefd3c16'
            ),
        ));
        $response = curl_exec($curl);
        $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        curl_close($curl);
        $search_result = json_decode($response);
        
       
        if($httpcode != 200)
        {
            return "fail";
        }
        
        return $search_result;

    }

``
SilenceBringer's avatar

@crystalmixz7 Heh Do you think you give some more details? Try to look to your response as we see it. You did api call to some 3rd side service (we don't know which one, because url is $this->api_url.'/api/bill') and return the response from the service

But - what is the response of the service? Is it array? How it looks like?

jlrdw's avatar
  • OFFSET is starting at
  • LIMIT is how many

So an offset of 5 with a limit of 5 would be page 2

An offset of 0 with a limit of 5 is page 1, etc.

So skip would be offset.

take would be limit.

I suggest looking up exactly how MySql handles this.

1 like

Please or to participate in this conversation.