['name' => 'pid', 'title' => '父ID', 'type' => 'bigint', 'is_must' => '0'], 'name' => ['name' => 'name', 'title' => '字典值', 'type' => 'varchar', 'is_must' => '1'], 'title' => ['name' => 'title', 'title' => '字典名', 'type' => 'varchar', 'is_must' => '1'], 'status' => ['name' => 'status', 'title' => '状态:1 启用 2 关闭', 'type' => 'tinyint', 'is_must' => '0'], ]; public function child() { return $this->hasMany(get_class($this), 'pid', $this->getKeyName()); } public function parent() { return $this->hasOne(get_class($this), $this->getKeyName(), 'pid'); } public static function getDictValue($name, $value = '') { $list = Cache::get('dict_list_'.$name); if(!$list) { $parent = self::where('pid', 0)->where('name', $name)->first(); $list = $parent->child()->pluck('title', 'name')->toArray(); Cache::put('dict_list_' . $name, $list, 60 * 60); } if($value !== ''){ return $list[$value]; } return $list; } }