| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace KyleMassacre\Menus; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Collective\Html\HtmlFacade as HTML; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Contracts\Support\Arrayable as ArrayableContract; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Support\Arr; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Illuminate\Support\Facades\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Illuminate\Support\Str; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use KyleMassacre\Menus\Traits\CanHide; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @property string url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @property string route | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @property string title | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @property string name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @property string icon | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @property int parent | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @property array attributes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @property bool active | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @property int order | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * @property array badge | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | class MenuItem implements ArrayableContract | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     use CanHide; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * Array properties. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     protected $properties = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * The child collections for current menu item. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     protected $childs = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * The fillable attribute. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     protected $fillable = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         'url', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         'route', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         'title', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         'name', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         'icon', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         'parent', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         'attributes', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         'active', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         'order', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         'hideWhen', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         'badge', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         'class', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * Constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @param array $properties | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 26 |  |     public function __construct($properties = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 26 |  |         $this->properties = $properties; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 26 |  |         $this->fill($properties); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * Set the icon property when the icon is defined in the link attributes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @param array $properties | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 26 |  |     protected static function setIconAttribute(array $properties) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 26 |  |         $icon = Arr::get($properties, 'attributes.icon'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 26 |  |         if (!is_null($icon)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 1 |  |             $properties['icon'] = $icon; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 1 |  |             Arr::forget($properties, 'attributes.icon'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 | 1 |  |             return $properties; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 25 |  |         return $properties; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * Get random name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * @param array $attributes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     protected static function getRandomName(array $attributes) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         return substr(md5(Arr::get($attributes, 'title', Str::random(6))), 0, 5); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * Create new static instance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * @param array $properties | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @return static | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 26 |  |     public static function make(array $properties) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 | 26 |  |         $properties = self::setIconAttribute($properties); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 26 |  |         return new static($properties); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |      * Fill the attributes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |      * @param array $attributes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 | 26 |  |     public function fill($attributes) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 | 26 |  |         foreach ($attributes as $key => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 | 25 |  |             if (in_array($key, $this->fillable)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 | 25 |  |                 $this->{$key} = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |      * Create new menu child item using array. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |      * @param $attributes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      * @return $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 | 2 |  |     public function child($attributes) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 | 2 |  |         $this->childs[] = static::make($attributes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 | 2 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |      * Register new child menu with dropdown. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |      * @param $title | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |      * @param callable $callback | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      * @return $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 | 9 |  |     public function dropdown($title, \Closure $callback, $order = 0, array $attributes = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 | 9 |  |         $properties = compact('title', 'order', 'attributes'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 | 9 |  |         if (func_num_args() === 3) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |             $arguments = func_get_args(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |             $title = Arr::get($arguments, 0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |             $attributes = Arr::get($arguments, 2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |             $properties = compact('title', 'attributes'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 | 9 |  |         $child = static::make($properties); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 | 9 |  |         call_user_func($callback, $child); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 | 9 |  |         $this->childs[] = $child; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 | 9 |  |         return $child; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |      * Create new menu item and set the action to route. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |      * @param $route | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |      * @param $title | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |      * @param array $parameters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |      * @param array $attributes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |      * @return MenuItem | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 | 3 |  |     public function route($route, $title, $parameters = array(), $order = 0, $attributes = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 | 3 |  |         if (func_num_args() === 4) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |             $arguments = func_get_args(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |             return $this->add([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |                 'route' => [Arr::get($arguments, 0), Arr::get($arguments, 2)], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |                 'title' => Arr::get($arguments, 1), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |                 'attributes' => Arr::get($arguments, 3), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |             ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 | 3 |  |         $route = array($route, $parameters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 | 3 |  |         return $this->add(compact('route', 'title', 'order', 'attributes')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |      * Create new menu item  and set the action to url. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |      * @param $url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |      * @param $title | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |      * @param array $attributes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |      * @return MenuItem | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 | 6 |  |     public function url($url, $title, $order = 0, $attributes = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 | 6 |  |         if (func_num_args() === 3) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |             $arguments = func_get_args(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |             return $this->add([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |                 'url' => Arr::get($arguments, 0), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |                 'title' => Arr::get($arguments, 1), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |                 'attributes' => Arr::get($arguments, 2), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |             ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 | 6 |  |         return $this->add(compact('url', 'title', 'order', 'attributes')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |      * Add new child item. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |      * @param array $properties | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |      * @return $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 | 9 |  |     public function add(array $properties) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 | 9 |  |         $item = static::make($properties); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 | 9 |  |         $this->childs[] = $item; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 | 9 |  |         return $item; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |      * Add new divider. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |      * @param int $order | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |      * @return self | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 | 1 |  |     public function addDivider($order = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 | 1 |  |         $item = static::make(array('name' => 'divider', 'order' => $order)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 | 1 |  |         $this->childs[] = $item; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 | 1 |  |         return $item; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |      * Alias method instead "addDivider". | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |      * @param int $order | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |      * @return MenuItem | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 | 1 |  |     public function divider($order = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 | 1 |  |         return $this->addDivider($order); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |      * Add dropdown header. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |      * @param $title | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |      * @return $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 | 2 |  |     public function addHeader($title) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 | 2 |  |         $item = static::make(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 | 2 |  |             'name' => 'header', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 | 2 |  |             'title' => $title, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 | 2 |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 | 2 |  |         $this->childs[] = $item; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 | 2 |  |         return $item; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |      * Same with "addHeader" method. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |      * @param $title | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |      * @return $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 | 2 |  |     public function header($title) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 | 2 |  |         return $this->addHeader($title); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |     public function addBadge(string $type, $text) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |         $properties = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |             'type' => $type, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |             'text' => $text, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |             'name' => 'badge', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |         $item = static::make($properties); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |         $this->badge = $properties; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |         return $item; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |      * Get childs. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 | 10 |  |     public function getChilds() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 | 10 |  |         if (config('menus.ordering')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 | 1 |  |             return collect($this->childs)->sortBy('order')->all(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 | 9 |  |         return $this->childs; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |      * Get url. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 | 3 |  |     public function getUrl() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 | 3 |  |         if ($this->route !== null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 | 1 |  |             return route($this->route[0], $this->route[1]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 | 2 |  |         if (empty($this->url)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |             return url('/#'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 | 2 |  |         return url($this->url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |      * Get request url. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 | 1 |  |     public function getRequest() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 | 1 |  |         return ltrim(str_replace(url('/'), '', $this->getUrl()), '/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |      * @param string $type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |      * @param $text | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  |     public function getBadge() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |         if($this->hasBadge()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  |             extract($this->badge); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |             return '<span class="' . $type . '">' . $text . '</span>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  |         //dd('badge is null'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  |      * Get icon. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  |      * @param null|string $default | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 | 3 |  |     public function getIcon($default = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 | 3 |  |         if ($this->icon !== null && $this->icon !== '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 | 1 |  |             return '<i class="' . $this->icon . '"></i>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 | 2 |  |         if ($default === null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 | 1 |  |             return $default; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 | 1 |  |         return '<i class="' . $default . '"></i>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  |      * Get properties. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 | 4 |  |     public function getProperties() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 | 4 |  |         return $this->properties; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 401 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 402 |  |  |      * Get HTML attribute data. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 403 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 404 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 405 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 406 | 1 |  |     public function getAttributes() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 407 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 408 | 1 |  |         $attributes = $this->attributes ? $this->attributes : []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 409 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 410 | 1 |  |         Arr::forget($attributes, ['active', 'icon']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 411 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 412 | 1 |  |         return HTML::attributes($attributes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 413 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 414 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 415 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 416 |  |  |      * Check is the current item divider. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 417 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 418 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 419 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 420 | 1 |  |     public function isDivider() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 421 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 422 | 1 |  |         return $this->is('divider'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 423 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 424 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 425 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 426 |  |  |      * Check is the current item divider. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 427 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 428 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 429 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 430 | 1 |  |     public function isHeader() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 431 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 432 | 1 |  |         return $this->is('header'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 433 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 434 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 435 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 436 |  |  |      * Check is the current item divider. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 437 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 438 |  |  |      * @param $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 439 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 440 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 441 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 442 | 2 |  |     public function is($name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 443 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 444 | 2 |  |         return $this->name == $name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 445 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 446 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 447 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 448 |  |  |      * Check is the current item has sub menu . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 449 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 450 |  |  |      * @return bool | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 451 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 452 | 1 |  |     public function hasSubMenu() | 
            
                                                                        
                            
            
                                    
            
            
                | 453 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 454 | 1 |  |         return !empty($this->childs); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 455 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 456 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 457 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 458 |  |  |      * Same with hasSubMenu. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 459 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 460 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 461 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 462 | 1 |  |     public function hasChilds() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 463 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 464 | 1 |  |         return $this->hasSubMenu(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 465 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 466 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 467 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 468 |  |  |      * Check the active state for current menu. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 469 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 470 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 471 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 472 |  |  |     public function hasActiveOnChild() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 473 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 474 |  |  |         if ($this->inactive()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 475 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 476 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 477 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 478 |  |  |         return $this->hasChilds() ? $this->getActiveStateFromChilds() : false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 479 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 480 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 481 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 482 |  |  |      * Get active state from child menu items. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 483 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 484 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 485 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 486 |  |  |     public function getActiveStateFromChilds() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 487 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 488 |  |  |         foreach ($this->getChilds() as $child) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 489 |  |  |             if ($child->inactive()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 490 |  |  |                 continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 491 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 492 |  |  |             if ($child->hasChilds()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 493 |  |  |                 if ($child->getActiveStateFromChilds()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 494 |  |  |                     return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 495 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 496 |  |  |             } elseif ($child->isActive()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 497 |  |  |                 return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 498 |  |  |             } elseif ($child->hasRoute() && $child->getActiveStateFromRoute()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 499 |  |  |                 return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 500 |  |  |             } elseif ($child->getActiveStateFromUrl()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 501 |  |  |                 return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 502 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 503 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 504 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 505 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 506 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 507 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 508 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 509 |  |  |      * Get inactive state. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 510 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 511 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 512 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 513 |  |  |     public function inactive() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 514 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 515 |  |  |         $inactive = $this->getInactiveAttribute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 516 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 517 |  |  |         if (is_bool($inactive)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 518 |  |  |             return $inactive; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 519 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 520 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 521 |  |  |         if ($inactive instanceof \Closure) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 522 |  |  |             return call_user_func($inactive); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 523 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 524 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 525 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 526 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 527 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 528 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 529 |  |  |      * Get active attribute. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 530 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 531 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 532 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 533 |  |  |     public function getActiveAttribute() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 534 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 535 |  |  |         return Arr::get($this->attributes, 'active'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 536 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 537 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 538 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 539 |  |  |      * Get inactive attribute. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 540 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 541 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 542 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 543 |  |  |     public function getInactiveAttribute() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 544 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 545 |  |  |         return Arr::get($this->attributes, 'inactive'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 546 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 547 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 548 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 549 |  |  |      * Get active state for current item. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 550 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 551 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 552 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 553 |  |  |     public function isActive() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 554 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 555 |  |  |         if ($this->inactive()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 556 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 557 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 558 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 559 |  |  |         $active = $this->getActiveAttribute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 560 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 561 |  |  |         if (is_bool($active)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 562 |  |  |             return $active; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 563 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 564 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 565 |  |  |         if ($active instanceof \Closure) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 566 |  |  |             return call_user_func($active); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 567 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 568 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 569 |  |  |         if ($this->hasRoute()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 570 |  |  |             return $this->getActiveStateFromRoute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 571 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 572 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 573 |  |  |         return $this->getActiveStateFromUrl(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 574 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 575 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 576 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 577 |  |  |      * Determine the current item using route. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 578 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 579 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 580 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 581 |  |  |     protected function hasRoute() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 582 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 583 |  |  |         return !empty($this->route); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 584 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 585 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 586 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 587 |  |  |      * Get active status using route. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 588 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 589 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 590 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 591 |  |  |     protected function getActiveStateFromRoute() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 592 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 593 |  |  |         return Request::is(str_replace(url('/') . '/', '', $this->getUrl())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 594 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 595 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 596 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 597 |  |  |      * Get active status using request url. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 598 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 599 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 600 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 601 |  |  |     protected function getActiveStateFromUrl() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 602 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 603 |  |  |         return Request::is($this->url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 604 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 605 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 606 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 607 |  |  |      * Set order value. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 608 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 609 |  |  |      * @param  int $order | 
            
                                                                                                            
                            
            
                                    
            
            
                | 610 |  |  |      * @return self | 
            
                                                                                                            
                            
            
                                    
            
            
                | 611 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 612 |  |  |     public function order($order) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 613 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 614 |  |  |         $this->order = $order; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 615 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 616 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 617 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 618 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 619 |  |  |     public function hasBadge() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 620 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 621 |  |  |         return !empty($this->badge); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 622 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 623 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 624 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 625 |  |  |      * Get the instance as an array. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 626 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 627 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 628 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 629 |  |  |     public function toArray() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 630 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 631 |  |  |         return $this->getProperties(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 632 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 633 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 634 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 635 |  |  |      * Get property. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 636 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 637 |  |  |      * @param string $key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 638 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 639 |  |  |      * @return string|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 640 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 641 | 4 |  |     public function __get($key) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 642 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 643 | 4 |  |         return isset($this->$key) ? $this->$key : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 644 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 645 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 646 |  |  |  |