|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Model; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
|
7
|
|
|
use Illuminate\Database\Eloquent\Model as EloquentModel; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class Menus. |
|
11
|
|
|
* |
|
12
|
|
|
* @property int $id |
|
13
|
|
|
* @property string $slug |
|
14
|
|
|
* @property string $title |
|
15
|
|
|
* @property string $icon |
|
16
|
|
|
* @property string $link |
|
17
|
|
|
* @property int $page_id |
|
18
|
|
|
* @property string $target |
|
19
|
|
|
* @property int $menu_id |
|
20
|
|
|
* @property int $order_id |
|
21
|
|
|
* @property boolean $enabled |
|
22
|
|
|
* @property boolean $required |
|
23
|
|
|
* @property int $creator_id |
|
24
|
|
|
* @property int $editor_id |
|
25
|
|
|
* |
|
26
|
|
|
* @property Carbon $deleted_at |
|
27
|
|
|
* @property Carbon $created_at |
|
28
|
|
|
* @property Carbon $updated_at |
|
29
|
|
|
* |
|
30
|
|
|
* @property Page page |
|
31
|
|
|
*/ |
|
32
|
|
|
class Menu extends EloquentModel |
|
33
|
|
|
{ |
|
34
|
|
|
/* |
|
35
|
|
|
* Laravel Deleting. |
|
36
|
|
|
* @ https://laravel.com/docs/5.5/eloquent#soft-deleting |
|
37
|
|
|
*/ |
|
38
|
|
|
use SoftDeletes; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* The table associated with the model. |
|
42
|
|
|
* |
|
43
|
|
|
* @var string |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $table = 'menus'; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Generate a link that the menu will visit when clicked. |
|
49
|
|
|
* |
|
50
|
|
|
* @return \Illuminate\Contracts\Routing\UrlGenerator|mixed|string |
|
|
|
|
|
|
51
|
|
|
*/ |
|
52
|
|
|
public function link() |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->page ? url($this->page->slug) : $this->link; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Relationship to the submenu table. |
|
59
|
|
|
* |
|
60
|
|
|
* @return Menu|\Illuminate\Database\Eloquent\Relations\HasMany |
|
61
|
|
|
*/ |
|
62
|
|
|
public function submenus() |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->hasMany(self::class, 'menu_id', 'id'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* A Menu can have a menu. |
|
69
|
|
|
* |
|
70
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne |
|
71
|
|
|
*/ |
|
72
|
|
|
public function parent() |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->hasOne(self::class, 'id', 'menu_id'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Menu belongs to a single Page. |
|
79
|
|
|
* |
|
80
|
|
|
* @return Page|\Illuminate\Database\Eloquent\Relations\BelongsTo |
|
81
|
|
|
*/ |
|
82
|
|
|
public function page() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->belongsTo(Page::class, 'page_id', 'id'); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Get the creators account name. |
|
89
|
|
|
* |
|
90
|
|
|
* @return Account|mixed |
|
|
|
|
|
|
91
|
|
|
*/ |
|
92
|
|
|
public function creator() : Account |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->hasOne(Account::class, 'creator_id', 'id'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Get the creator model of the eloquent model. |
|
99
|
|
|
* |
|
100
|
|
|
* @return Account|mixed |
|
|
|
|
|
|
101
|
|
|
*/ |
|
102
|
|
|
public function modifier() |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->belongsTo(Account::class, 'editor_id', 'id'); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.