@msslgomez I was able to resolve the issue with,
Controllers:
getTvDetails is my initial render of the page, and I lazy load tv Episodes.
public function getTvDetails($id)
{
$key = env("TMDB_API_KEY");
$data = Http::get("https://api.themoviedb.org/3/tv/{$id}?api_key={$key}&language=en-US")->json();
return Inertia::render('TV/Detail', [
"tvDetails" => TvDetailResource::make($data),
'tvEpisodes' => Inertia::lazy(fn() => App::call([$this, 'lazyLoadTvEpisodes'])),
]);
}
Then on click of a tab header:
public function lazyLoadTvEpisodes(Request $request)
{
$key = env("TMDB_API_KEY");
$season = $request->input('season');
$tvId = $request->input('tvId');
$tvEpisodes = Http::get("https://api.themoviedb.org/3/tv/{$tvId}/season/{$season}?api_key={$key}&language=en-US")->json();
return TvEpisodeResource::make($tvEpisodes);
}
}
and my form:
const form = useForm({
season: 1,
tvId: route().params.id,
})
const submit = (selectedTab) => {
// console.log(selectedTab);
const index = selectedTab.tab.index
const currentTab = props.tvDetails.data.seasons[index]
console.log(currentTab);
form.season = currentTab.season_number
router.reload({
data: form.data(),
only: ['tvEpisodes'],
preserveState: true,
preserveScroll: true,
onSuccess() {
console.log(props.tvEpisodes);
},
})
}
Thanks for the help!