这是一个二级分类
怎么遍历出这个二级分类
利用递归
public static function getLei($pid){
$date=DB::table('cates')->where('pid','=',$pid)->get();
$d=[];
foreach ($date as $key => $value) {
$value->sub=self::getLei($value->id);
$d[]=$value;
}
return $date;
}
调用
public function aa()
{ $list=self::getLei(0);
return view('',['list'=>$list]);
}
遍历
@foreach($leilei as $row)
{{$row->name}}
@foreach($row->sub as $rows)
@endforeach@endforeach