'int', 'is_root' => 'int', 'is_parent' => 'int', 'pid' => 'int', 'name' => 'varchar', 'title' => 'varchar', 'badge' => 'varchar', 'path' => 'varchar', 'component' => 'varchar', 'icon' => 'varchar', 'redirect' => 'varchar', 'affix' => 'int', 'hidden' => 'int', 'dot' => 'int', 'noKeepAlive' => 'int', 'alwaysShow' => 'int', 'isCustomSvgIcon' => 'int', 'tabHidden' => 'int', 'sort' => 'int', 'cascade' => 'varchar', 'status' => 'int', 'create_user' => 'int', 'update_user' => 'int', 'create_at' => 'datetime', 'update_at' => 'datetime', 'parent_path' => 'varchar', 'delete_at' => 'datetime' ]; protected $append = [ 'parentName', 'pathName', 'status_txt', 'level', ]; public function getAlwaysShowAttr($value) { return $value == 1; } public function statusList() { return [1 => '可用', 2 => '不可用']; } public function getStatusTxtAttr($value, $data) { $value = $value ? $value : (isset($data['status']) ? $data['status'] : ''); $statusList = $this->statusList(); return isset($statusList[$value]) ? $statusList[$value] : ''; } public function menurequest() { return $this->hasMany(Menurequest::class,"menu_id","menu_id"); } public function getParentNameAttr($value, $data) { $value = $value ? $value : (isset($data['pid']) ? $data['pid'] : ''); $MenuList = cache('MENULIST'); if (empty($MenuList)) { $MenuList = self::column('title', 'menu_id'); cache('MENULIST', $MenuList, 7200); } return isset($MenuList[$value]) ? $MenuList[$value] : '顶级菜单'; } public function getPathNameAttr($value, $data) { $value = isset($data['parent_path']) ? $data['parent_path'] : ''; if (!empty($value)) { $pids = explode(',', $value); $MenuList = cache('MENULIST'); if (empty($MenuList)) { $MenuList = self::column('title', 'menu_id'); cache('MENULIST', $MenuList, 7200); } $titles = []; foreach ($pids as $pid) { $titles[] = isset($MenuList[$pid]) ? $MenuList[$pid] : ''; } $titles = array_filter($titles); return implode('/', $titles); } else { return ''; } } public function getLevelAttr($value, $data) { $value = isset($data['parent_path']) ? $data['parent_path'] : ''; $pids = []; if (!empty($value)) { $pids = explode(',', $value); }; return count($pids); } }