If you get you correctly, you can use relationships. A category has many sub category.
For dropdown menu, I think you have to use any standard JS library to synchronize that.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
below is the table which has id,name,parent_id. the parent_id is the foreign key which refers to id column (categories and subcategories)
id name parent_id
1 Elect NULL
2 Cam NULL
3 Appliances NULL
4 Smart Phone 1
5 Tablets 1
6 Refrigi 3
i have queried from the database to display the categories using below query
DB::table('categories')->select('name')->where('parent_id', '!=', NULL)->get();
above query display the categories name in the drop down
how to query to display the subcategories name based on particular category
for example if the Appliances is the category when the user clicks on the drop down it should display the Refrigi as the subcategory only. any help.??
Thanks,
Please or to participate in this conversation.