Advertisement
apl-mhd

recursive tree

Dec 26th, 2018
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.56 KB | None | 0 0
  1. function categoryTree($id)
  2.              {
  3.             $data='';
  4.             $all_childs = \App\Models\Category::where('parent_id', $id)->get();
  5.             if(!empty($all_childs))
  6.             {
  7.  
  8.                 echo "<ul>";
  9.                 foreach ($all_childs as $child)
  10.                 {
  11.                     echo "<li> <a href='#'>";
  12.                     echo $child->name .' '. $child->id ;
  13.                     echo "</a></li>";
  14.                     categoryTree($child->id);
  15.                 }
  16.                 echo "</ul>";
  17.             }
  18.  
  19.  
  20.              }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement