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

dmytroshved's avatar

Question about subcategories for filtering data. Laravel 11

Hey everyone, I have categories & subcategories (categories have a relation with subcategories, for one category there is many subcategories)

I have a question:

Is it acceptable for a recipe to have a category but no subcategory? What impact does this have? Will this be a bug? Will this interfere with filtration?

Would be gratefull for some advices from your experience

0 likes
4 replies
jlrdw's avatar
jlrdw
Best Answer
Level 75

Well a post here may not have a reply. But usually a product has subcategories.

Like:

Lawn mowers 

---Riding
---Push

But in some cases maybe no subcategories. But no, nothing wrong with that.

Will this interfere with filtration?

There are for example cases when there are no child records.

For example an accounts receivable report. Some months a company doesn't owe, so no child records, you just show 0 balance that month.

1 like
Snapey's avatar

Is it acceptable for a recipe to have a category but no subcategory?

Thats up to you. You have to code it for the solution you want.

I would like to ask you, If the user selects a subcategory, it shows recipes in that subcategory. But what if they select category? Do you show all recipes that are in any of the subcategories for that category?

dmytroshved's avatar

@Snapey My filter has two selectors:

  1. Dish Category
  2. Dish Subcategory

There's "dependent dropdown" logic here (I am using Livewire for that logic).

  • If the user selects a category (in the first selector), the subcategories for that category will appear in the Dish Subcategory selector (the second one). However, if the user hasn't selected a category, the subcategory selector will be disabled.

  • Alternatively, the user can specify a category without specifying a subcategory, and in that case, I'll display all recipes that belong to the chosen category.

I hope it is clear

Thanks for reply

jlrdw's avatar

@Dmytro_Shved You could also show a message where the subcategory drop down is stating something like:

No subcategories for this category

Just example.

1 like

Please or to participate in this conversation.