title: Looping through multiple pages of a JSON request (Guzzle, Laravel, PHP)
body: <p>New dev here so I am sorry if this is a simple question or something like that but haven't been able to find exactly what I am looking for (it totally could be that I am not asking the question correctly either) Basically I have a paginated list coming back from an api and I am not sure what the logic would be to be able to cycle through those pages. Here is the code that I have so far that works perfectly for the first page lol.</p>
  
  <pre><code>    public function handle()
      {
          //This is the artisan command that runs on a timer and gets all the ticket and update fields that are needed and saves them to the database.
          $tickets = $this-&gt;pullTicketSummary();
          collect($tickets['data'])
              -&gt;each(function ($currTicket) {
  
                  $ticketRow = Tickets::query()-&gt;firstOrCreate(['ticket_id' =&gt; $currTicket['id']]);
                  $ticketRow-&gt;status_id = $currTicket['status']['id'];
                  $ticketRow-&gt;category_id = $currTicket['category']['id'];
                  $ticketRow-&gt;user_id = $currTicket['assigned_to']['id'];
                  $ticketRow-&gt;jira_issue_id = $currTicket['jira_issue_id'];
                  $ticketRow-&gt;save();
  
                  collect($currTicket['updates'])-&gt;each(function ($update) use ($currTicket){
                      $updateRow = Update::query()-&gt;firstOrCreate(['update_id' =&gt; $update['update_id']]);
                      $updateRow-&gt;ticket_id = $currTicket['id'];
                      $updateRow-&gt;assignee_change = $update['assignee_change'];
                  });
              });
          Log::info('All tickets and updates were pulled successfully');
      }
  
      protected function pullTicketSummary()
      {       //Function makes the guzzle request and returns the response from the happyfox api
              $client = new Client();
              $request = $client-&gt;get('https://happyfox.com/api/1.1/json/tickets/?size=50&amp;page=1',
                  ['auth' =&gt; ['N/A']);
              $response = json_decode($request-&gt;getBody()-&gt;getContents(), true);
              return $response;
  
      }
  </code></pre>
  
  <p>With the fact that I am new if this is something that has been answered before that I missed please just shoot me over a link or if you are aware of any documentation that would help me get to the answer on my own that would be awesome! thanks!</p>