I'm very new to Inertia and struggling to figure out the correct way to load additional data after some interaction with the user. I see posts referring to usePage().$inertia.get() but I think this is legacy as I cannot find documentation anywhere. In the current docs I see the explanation for partial reloads which might be what I need, but I'm just not sure how to pass parameters with the reload or if that's even the right way!
So I have a Vue Page that receives a Collection of 'Topics' from my 'TopicController'. The Vue page loops through the collection and shows a component for each Topic.
From my controller:
public function index()
{
return Inertia::render('Topic/Index',[
'topics' => Auth::check() ? Topic::mine()->orderBy('name')->with('descendants')->withCount('flashcards')->get() : null,
]);
}
When the user clicks on a Topic I want to collect more data for that specific Topic from the backend but I need to be able to pass back the topic id so that the backend can gather the additional data, but I'm not sure how to pass back the topic id as part of the reload() or how to get the Controller to return it. Or should I be using $inertia.get() instead?
I'm guessing it's something like:
router.reload({ only: ['topicData'], 'topicid': topic.id})
and in my controller:
public function index($topicId = null)
{
return Inertia::render('Topic/Index',[
'topics' => Auth::check() ? Topic::mine()->orderBy('name')->with('descendants')->withCount('flashcards')->get() : null,
'topicData' => Inertia::lazy(fn () => getSomeExtraTopicData($topicId)),
]);
}
In case you think I should just pass all the topic data in the initial load, the additional topic data requires a couple of database calls to get some related models and it would be too expensive to do that for each topic in advance.
I hope that makes some sense!
TIA