22
33namespace Hexadog \MenusManager \Traits ;
44
5+ use Closure ;
56use Hexadog \MenusManager \Item ;
67use Illuminate \Support \Collection ;
78
@@ -68,9 +69,9 @@ public function findBy(string $key, string $value): ?Item
6869 *
6970 * @return mixed
7071 */
71- public function findByTitleOrAdd (string $ title , array $ attributes = []): ?Item
72+ public function findByTitleOrAdd (string | Closure $ title , array $ attributes = []): ?Item
7273 {
73- if (!($ item = $ this ->findBy ('title ' , $ title ))) {
74+ if (!($ item = $ this ->findBy ('title ' , $ title instanceof Closure ? $ title () : $ title ))) {
7475 $ item = $ this ->add (compact ('title ' , 'attributes ' ));
7576 }
7677
@@ -80,7 +81,7 @@ public function findByTitleOrAdd(string $title, array $attributes = []): ?Item
8081 /**
8182 * Add new header menu item.
8283 */
83- public function header (string $ title , array $ attributes = []): Item
84+ public function header (string | Closure $ title , array $ attributes = []): Item
8485 {
8586 return $ this ->add (compact ('title ' , 'attributes ' ))->asHeader ();
8687 }
@@ -102,15 +103,15 @@ public function items()
102103 *
103104 * @param mixed $route
104105 */
105- public function route ($ route , string $ title , array $ attributes = []): Item
106+ public function route ($ route , string | Closure $ title , array $ attributes = []): Item
106107 {
107108 return $ this ->add (compact ('route ' , 'title ' , 'attributes ' ));
108109 }
109110
110111 /**
111112 * Register new menu item using url.
112113 */
113- public function url (string $ url , string $ title , array $ attributes = []): Item
114+ public function url (string $ url , string | Closure $ title , array $ attributes = []): Item
114115 {
115116 return $ this ->add (compact ('url ' , 'title ' , 'attributes ' ));
116117 }
0 commit comments