用laravel 做无限极分类;
找了很多资料;
假大空;
有很多都是残缺的;
而且达不到预期;
无法做到无限极;
今天分享下代码;
很简单的几段代码就能实现;
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Model\Category;
use App\Models\M3Result;
use Illuminate\Http\Request;
use App\Http\Requests;
use Illuminate\Support\Facades\Crypt;
use Validator;
class CategoryController extends CommonController
{
public function tree($parent_id = 0)
{
$rows = Category::where('parent_id', $parent_id)->orderBy('sort_order','ASC')->get();
$arr = array();
if (sizeof($rows) != 0){
foreach ($rows as $key => $val){
$val['list'] = $this->tree($val['cat_id']);
$arr[] = $val;
}
return $arr;
}
}
public function category_list(Request $request){
$Category= $this->tree();
return view('admin.category_list',[
'date'=>$Category
]);
}
}
如果对您有所帮助的话 还请帮忙 点下 小 心心!