|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Chuckbe\Chuckcms\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Eloquent; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @property int $id |
|
9
|
|
|
* @property string $label |
|
10
|
|
|
* @property string $link |
|
11
|
|
|
* @property string $class |
|
12
|
|
|
* @property int $menu |
|
13
|
|
|
* @property int $sort |
|
14
|
|
|
* @property int $parent |
|
15
|
|
|
* @property int $depth |
|
16
|
|
|
*/ |
|
17
|
|
|
class MenuItems extends Eloquent |
|
18
|
|
|
{ |
|
19
|
|
|
protected $table = null; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The attributes that are mass assignable. |
|
23
|
|
|
* |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $fillable = [ |
|
27
|
|
|
'label', 'link', 'parent', 'sort', 'class', 'menu', 'depth', |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct(array $attributes = []) |
|
31
|
|
|
{ |
|
32
|
|
|
//parent::construct( $attributes ); |
|
33
|
|
|
$this->table = config('menu.table_prefix').config('menu.table_name_items'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function getsons($id) |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->where('parent', $id)->get(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function getall($id) |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->where('menu', $id)->orderBy('sort', 'asc')->get(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public static function getNextSortRoot($menu) |
|
47
|
|
|
{ |
|
48
|
|
|
return self::where('menu', $menu)->max('sort') + 1; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function getLinkAttribute() |
|
52
|
|
|
{ |
|
53
|
|
|
if (strpos($this->attributes['link'], 'page:') !== false) { |
|
54
|
|
|
$page_id = explode(':', $this->attributes['link'])[1]; |
|
55
|
|
|
|
|
56
|
|
|
return Page::getUrl($page_id); |
|
57
|
|
|
} else { |
|
58
|
|
|
return $this->attributes['link']; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function getRawLinkAttribute() |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->attributes['link']; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getTypeAttribute() |
|
68
|
|
|
{ |
|
69
|
|
|
if (strpos($this->attributes['link'], 'page:') !== false) { |
|
70
|
|
|
return 'Page'; |
|
71
|
|
|
} else { |
|
72
|
|
|
return 'Link'; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|