Hi all,
I'm just learning Nova and running into an issue with filtering relationship belongsto fields based off a parent value in select fields.
Structure is as follows:
category has many subcategories | subcategories belongsto category
category has many items (inventory items) | items belongsto category
items belongsto subcategories | subcategories has many items
the associated models have the relationships defined and everything works with foreign keys, however the subcategory select field shows all subcategories.how do I filter the subcategory select field to only show the subcategories based off the id of the value selected in the category field?
ex: category = overhead (id 1)
subcategory select field should only return the title where 'category_id' = 1 on the subcategories table.
What I've tried:
BelongsTo::Make('Subcategory'),
This works, however the list isn't filtered based off category value.
Select::make('Subcategory')->options(\App\Models\Inventory\Subcategory::pluck('title')->where('category_id', '=', '2')),
This doesnt return any results, not sure what I did wrong, also not sure how to make it dynamic for the category value.
BelongsTo::make('Subcategory')->resolveUsing(\App\Models\Inventory\Subcategory::pluck('title')->where('id', '=', '2')),
This doesnt return any results, not sure what I did wrong, also not sure how to make it dynamic for the category value.