Closed chammeow closed 3 years ago
The query doesn't select from the expression by default. Add this to your method:
$merchantBranchCategoryListQuery->from('category_path');
The query doesn't select from the expression by default. Add this to your method:
$merchantBranchCategoryListQuery->from('category_path');
Thank you very much. I changed my approach using the adjacent list which is more convenient. I used the custom path added to my Model and add the tree() and toTree() function.
THANK YOU VERY MUCH.
Please help. I'm doing an eloquent selection for the list of categories with its Hierarchical Data and need to get the path names of categories to subcategories (eg. Electronics > Mobile Phones > Android Phones) but these path names not appearing on my GET method. Here is my code.
CONTROLLER
I've tried to check the SQL string for $merchantBranchCategoryList (eg. $merchantBranchCategoryListQuery->toSql()) but the ACTUAL return is
with recursive category_path (id, title, path) as (SELECT name as path FROM merchant_branch_categories WHERE parent_id IS NULL UNION ALL SELECT c.id, c.name, CONCAT(cp.path, ' > ', c.name) FROM category_path AS cp JOIN merchant_branch_categories AS c ON cp.id = c.parent_id) select * from merchant_branch_categories
I must be expecting
with recursive category_path (id, title, path) as (SELECT name as path FROM merchant_branch_categories WHERE parent_id IS NULL UNION ALL SELECT c.id, c.name, CONCAT(cp.path, ' > ', c.name) FROM category_path AS cp JOIN merchant_branch_categories AS c ON cp.id = c.parent_id) select * from category_path
PLEASE HELP ME TO UNDERSTAND.