8
8
trait HasItems
9
9
{
10
10
/**
11
- * The items collection
11
+ * The items collection.
12
12
*
13
13
* @var Collection
14
14
*/
15
15
protected $ items ;
16
16
17
17
/**
18
- * Add new item
18
+ * Magic method to manipulate items Collection with ease.
19
19
*
20
- * @param array $attributes
21
- *
22
- * @return Item
20
+ * @param string $method_name
21
+ * @param array $args
22
+ */
23
+ public function __call ($ method_name , $ args )
24
+ {
25
+ if (!method_exists ($ this , $ method_name )) {
26
+ return call_user_func_array ([$ this ->items , $ method_name ], $ args );
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Add new item.
23
32
*/
24
33
public function add (array $ attributes = []): Item
25
34
{
@@ -35,22 +44,15 @@ public function add(array $attributes = []): Item
35
44
}
36
45
37
46
/**
38
- * Add new divider menu item
39
- *
40
- * @param array $attributes
41
- *
42
- * @return Item
47
+ * Add new divider menu item.
43
48
*/
44
49
public function divider (array $ attributes = []): Item
45
50
{
46
51
return $ this ->add (compact ('attributes ' ))->asDivider ();
47
52
}
48
53
49
54
/**
50
- * Find item by key and value
51
- *
52
- * @param string $key
53
- * @param string $value
55
+ * Find item by key and value.
54
56
*
55
57
* @return mixed
56
58
*/
@@ -62,10 +64,7 @@ public function findBy(string $key, string $value): ?Item
62
64
}
63
65
64
66
/**
65
- * Find item by given title or add it
66
- *
67
- * @param string $title
68
- * @param array $attributes
67
+ * Find item by given title or add it.
69
68
*
70
69
* @return mixed
71
70
*/
@@ -79,20 +78,15 @@ public function findByTitleOrAdd(string $title, array $attributes = []): ?Item
79
78
}
80
79
81
80
/**
82
- * Add new header menu item
83
- *
84
- * @param string $title
85
- * @param array $attributes
86
- *
87
- * @return Item
81
+ * Add new header menu item.
88
82
*/
89
83
public function header (string $ title , array $ attributes = []): Item
90
84
{
91
85
return $ this ->add (compact ('title ' , 'attributes ' ))->asHeader ();
92
86
}
93
87
94
88
/**
95
- * Get items
89
+ * Get items.
96
90
*
97
91
* @return Collection
98
92
*/
@@ -104,45 +98,20 @@ public function items()
104
98
}
105
99
106
100
/**
107
- * Register new menu item using registered route
101
+ * Register new menu item using registered route.
108
102
*
109
103
* @param mixed $route
110
- * @param string $title
111
- * @param array $attributes
112
- *
113
- * @return Item
114
104
*/
115
105
public function route ($ route , string $ title , array $ attributes = []): Item
116
106
{
117
107
return $ this ->add (compact ('route ' , 'title ' , 'attributes ' ));
118
108
}
119
109
120
110
/**
121
- * Register new menu item using url
122
- *
123
- * @param string $url
124
- * @param string $title
125
- * @param array $attributes
126
- *
127
- * @return Item
111
+ * Register new menu item using url.
128
112
*/
129
113
public function url (string $ url , string $ title , array $ attributes = []): Item
130
114
{
131
115
return $ this ->add (compact ('url ' , 'title ' , 'attributes ' ));
132
116
}
133
-
134
- /**
135
- * Magic method to manipulate items Collection with ease
136
- *
137
- * @param string $method_name
138
- * @param array $args
139
- *
140
- * @return void
141
- */
142
- public function __call ($ method_name , $ args )
143
- {
144
- if (!method_exists ($ this , $ method_name )) {
145
- return call_user_func_array ([$ this ->items , $ method_name ], $ args );
146
- }
147
- }
148
117
}
0 commit comments