3 years ago

Mailgun, how to implement Mailgun response - pagination on a blade view?

Posted 3 years ago by P-Torres


I'm working with Mailgun's API, I'm trying to implement pagination when displaying the received data.

I have the following response from Mailgun.

{#383 ▼
  +"http_response_body": {#381 ▼
    +"items": array:10 [▶]
    +"paging": {#382 ▼
      +"first": "https://api.mailgun.net/v2/lists/[email protected]/members/pages?page=first&limit=10"
      +"last": "https://api.mailgun.net/v2/lists/[email protected]/members/pages?page=last&limit=10"
      +"next": "https://api.mailgun.net/v2/lists/[email protected]/members/pages?page=next&address=email-address-a%40domain.com&limit=10"
      +"previous": "https://api.mailgun.net/v2/lists/[email protected]/members/pages?page=prev&address=email-adress-b%40domain.com&limit=10"
  +"http_response_code": 200

On my controller I have the following:

public function members($address)
        # Instantiate the client.
        $mgClient = new Mailgun(env('MAILGUN_SECRET'));

        # Issue the call to the client.
        $result = $mgClient->get("lists/$address/members/pages", array(
            'limit'      =>  10

        return view('dash.members.show', compact('result'));

My view looks like this:

<div class="table-responsive">
    <table class="table table-striped table-hover dev-table-row-vertical-middle">
            <th>E-mail Address</th>
            @foreach($result->http_response_body->items as $obj)
                    <td>{{ $obj->name }}</td>
                    <td>{{ $obj->address }}</td>

<ul class="pagination">
    <li><a href="{{ $result->http_response_body->paging->first }}">First</a></li>
    <li><a href="{{ $result->http_response_body->paging->previous }}">Previous</a></li>
    <li><a href="{{ $result->http_response_body->paging->next }}">Next</a></li>
    <li><a href="{{ $result->http_response_body->paging->last }}">Last</a></li>

Can anyone guide me on how the code needs to be in order for the pagination to work?

I have tried many different approaches, I feel first I need to understand what needs to happen, anyone?

Thank you.

Please sign in or create an account to participate in this conversation.