/** * 编辑用户的时候的表单验证 * * @access public */ public function edit(\App\Services\Admin\User\Param\UserSave $data) { $rules = array('name' => 'required', 'realname' => 'required', 'group_id' => 'required|numeric|min:1', 'mobile' => 'required'); $messages = array('name.required' => Lang::get('user.account_name_empty'), 'realname.required' => Lang::get('user.realname_empty'), 'group_id.required' => Lang::get('user.group_empty'), 'group_id.numeric' => Lang::get('user.group_empty'), 'group_id.min' => Lang::get('user.group_empty'), 'mobile.required' => Lang::get('user.mobile_empty')); if (!empty($data->password)) { $rules['password'] = '******'; $messages['password.required'] = Lang::get('user.password_empty'); } $validator = Validator::make($data->toArray(), $rules, $messages); if ($validator->fails()) { $this->errorMsg = $validator->messages()->first(); return false; } return true; }
/** * user save params */ public function userSaveParams($data) { $params = new UserSave(); $params->setAttributes($data); return $params; }