Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ZeeshanNB's avatar

How to pass variables from parent to child resources in laravel nova

I am attempting to refine the displayed levels based on the combination of category_id and user_id, aiming to retrieve only the levels associated with a particular user within a specific category.

The situation unfolds as follows: I have a user resource that exhibits a BelongsToMany relationship with categories through the intermediary category_user_progress pivot table.

Upon clicking on a category, the system redirects me to the corresponding category resource. Here, another relationship comes into play: MorphedByMany to get levels, facilitated by the category_level_user_progress_pivot table, which incorporates user_id, category_id, and level_id.

The challenge lies in the fact that this configuration retrieves all the levels affiliated with the chosen category, without considering the selected user from the initial step.

In essence, my objective is to selectively filter the levels within a specific category, based on the user's association with that category. I initially attempted to convey the user's ID from the user resource to the category resource, and subsequently pass it along from the category resource to the level resource to narrow down the level records. Unfortunately, I haven't come across a definitive solution to fulfill this specific scenario.

In user resource: BelongsToMany::make(ucfirst(__('categories')), 'categoriesProgress', CategoryWrapper::class)

In Category Resource : BelongsToMany::make(ucfirst(__('levels')), 'levelProgress', LevelWrapper::class)

Is there a viable approach to achieve this functionality?

0 likes
0 replies

Please or to participate in this conversation.