模型层:
public static function getinfo($where=[])
{
return self::withTrashed()->where($where)->get();
}```
控制器:
public function create()
{
$data= House::getinfo();
d
a
t
a
=
data=
data=this->getTree($data);
return view(“admin.house.houseadd”,compact(“data”));
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201202193754144.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xrcWxxbGxxeQ==,size_16,color_FFFFFF,t_70)
BaseController:
//递归处理数据
public function getTree(
d
a
t
a
,
data,
data,pid=0,$level=1)
{
static
n
e
w
d
a
t
a
=
[
]
;
f
o
r
e
a
c
h
(
newdata=[]; foreach (
newdata=[];foreach(data as
k
=
>
k=>
k=>v){
if (
v
[
"
p
i
d
"
]
=
=
v["pid"]==
v["pid"]==pid){
v
[
"
l
e
v
e
l
"
]
=
v["level"]=
v["level"]=level;
n
e
w
d
a
t
a
[
]
=
newdata[]=
newdata[]=v;
t
h
i
s
−
>
g
e
t
T
r
e
e
(
this->getTree(
this−>getTree(data,
v
[
"
i
d
"
]
,
v["id"],
v["id"],level+1);
}
}
return $newdata;
}
前台:
//添加前台展示
Route::get("create","ArticleController@create")->name("article.create");
数据库: