'禁用',1=>'正常']; protected $appends = [ 'gender_text', 'status_text' ]; public function getGenderTextAttribute($value) { $value = $value ? $value : $this->gender; return isset(self::$_GENDER[$value]) ? self::$_GENDER[$value] : ''; } public function getStatusTextAttribute($value) { $value = $value ? $value : $this->status; return isset(self::$_STATUS[$value]) ? self::$_STATUS[$value] : ''; } /** * 获取单个用户信息 * @param int $id * @param string $field * @return object */ public static function getUserInfo($id,$field = '*') { return self::select($field)->find($id); } /** * 获取用户数组 * id为键,name为值 * @return array */ public static function getUserArray() { $list = self::select('id','nick_name') ->where('status',1) ->whereNull('deleted_at') ->get(); $array = []; if(count($list) > 0){ foreach ($list as $value) { $array[$value->id] = $value->nick_name; } } return $array; } }