getResponseFromApi($current_page); $last_page = $response->object()->last_page; $this->command->info('Last Page: ' . $last_page); $podcast = Podcast::find(1); while ($current_page <= $last_page) { $this->command->info('Getting Page ' . $current_page); foreach ($response->object()->data as $episode) { $podcastEpisode = Episode::where('title', $episode->title)->first(); if (!$podcastEpisode) { $podcastEpisode = Episode::factory()->state([ 'podcast_id' => 1, 'episode_date' => Carbon::parse($episode->show_date), 'published' => (bool)$episode->published, 'artwork_id' => null, 'slug' => $episode->episode_number . '_' . Str::slug($episode->title), 'title' => $episode->title, 'mp3' => $episode->link, 'created_at' => Carbon::parse($episode->created_at), 'updated_at' => Carbon::parse($episode->updated_at), 'legacy_id' => $episode->id ?? null ])->create(); } else { $podcastEpisode->legacy_id = $episode->id ?? null; if ($podcastEpisode->isDirty()) { $podcastEpisode->save(); } } $this->command->info('Created ' . $episode->show_date . ' - (' . $episode->episode_number . ') ' . $episode->title); } $current_page++; $response = $this->getResponseFromApi($current_page); } } private function getResponseFromApi($current_page) { $response = Http::timeout(180) ->get('https://noagendaartgenerator.com/episodesjson?p=7476&page=' . $current_page); return $response; } }