forked from modstart/ModStartBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlogCategory.php
More file actions
63 lines (54 loc) · 1.35 KB
/
Copy pathBlogCategory.php
File metadata and controls
63 lines (54 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Module\Blog\Model;
use Illuminate\Database\Eloquent\Model;
use ModStart\Core\Dao\ModelUtil;
class BlogCategory extends Model
{
protected $table = 'blog_category';
public static function getTreeList()
{
$models = ModelUtil::all(BlogCategory::class, [], ['*'], ['sort' => 'asc']);
$nodes = [];
foreach ($models as $model) {
$nodes[] = [
'id' => $model['id'],
'pid' => $model['pid'],
'title' => $model['title'],
'sort' => $model['sort']
];
}
return \ModStart\Core\Util\TreeUtil::nodesToTree($nodes, 0, 'id', 'pid', 'sort');
}
public function children()
{
return $this->hasMany(BlogCategory::class, 'pid', 'id');
}
public function parent()
{
return $this->belongsTo(BlogCategory::class, 'pid', 'id');
}
/**
* 获取树形结构的父级ID字段名
* @return string
*/
public function getTreeParentIdField()
{
return 'pid';
}
/**
* 获取树形结构的排序字段名
* @return string
*/
public function getTreeSortField()
{
return 'sort';
}
/**
* 获取树形结构的标题字段名
* @return string
*/
public function getTreeTitleField()
{
return 'title';
}
}