enter code here
Does any one can advice me how to remove the icon for main category havent's sub-categories. I have pass to show sub-categories under main category.
Here is my code: [enter image description here][1]
My view:
[blade View][2] [1]: https://i.stack.imgur.com/MbDuB.png [2]: https://i.stack.imgur.com/ieAqL.png
My Update with code
public static function showCategories($categories, $parent_id = 0)
{
$class ='';
$html = ""; //init
$flag = false;
foreach ($categories as $row) {
if ($row['parent_id'] == $parent_id) {
//we have a category
$link =self::linkCategory($row['category_id'],$row['name']);
$html .= '<ul id="accordion" class="accordion">
<li>
<div class="link accordion-title"><a href="'.$link.'">'.$row['name'].'</a><i class="fa fa-chevron-down"></i></div>';
$html .= "<ul class='submenu'>";
foreach ($categories as $subcat) {
$link =self::linkCategory($subcat['category_id'],$subcat['name']);
if ($subcat['parent_id'] ==$row['category_id']){
//we have a subcategory
$html .= '<li><a href="'.$link.'">'.$subcat['name'].'</a></li>';
}
}
$html .= "</ul>";
$html .= "</li>";
$html .= "</ul>";
}
}
return $html;
//call it blade $menu = URL::showCategories($itemCategory);
first of all its a bad practice that you use HTML in control, you have to use HTML only in blade sec you can do that by making the relation between categories and itself to get the sub cat to every cat then if your blade while you are looping it u can easily use Count() to get number of sub cat if it bigger than 0
add icon if don't add it
@if(Count($cat->sub) > 0)
<i class="icon-class">
@endif
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.