12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace App\Http\Requests;
- use Illuminate\Foundation\Http\FormRequest;
- class UserRequest extends FormRequest
- {
- /**
- * Determine if the user is authorized to make this request.
- *
- * @return bool
- */
- public function authorize()
- {
- return true;
- }
- /**
- * Get the validation rules that apply to the request.
- *
- * @return array
- */
- public function rules()
- {
- switch ($this->getMethod()) {
- case "PUT":
- return [
- 'sex' => 'in:1,2',
- 'feed_sex' => 'in:1,2',
- 'nickname' => 'between:1,12',
- 'height' => 'integer|between:150,200',
- 'introduce' => 'max:180',
- 'expect' => 'max:180',
- 'qq' => ['integer', 'regex:/^[0-9_]{5,10}$/'],
- 'weixin' => ['regex:/^[a-zA-Z]{1}[-_a-zA-Z0-9]{5,19}$/'],
- 'school' => 'string',
- 'age' => ["before_or_equal:-18year", "after_or_equal:-100year"]
- ];
- break;
- default:
- return [];
- }
- }
- public function messages()
- {
- return [
- 'sex.*' => '性别只能选取[男/女]',
- 'feed_sex.*' => '性取向只能选取[男/女]',
- 'weixin.*' => '请输入正确的微信号',
- 'qq.*' => '请输入正确的QQ号',
- 'school.*' => '请输入正确的学校全称',
- 'age.before_or_equal' => '生日 必须18周岁以上',
- 'age.after_or_equal' => '生日 必须100周岁以下',
- ];
- }
- public function attributes()
- {
- return [
- 'sex' => '性别',
- 'feed_sex' => '性取向',
- 'nickname' => '昵称',
- 'introduce' => '个性签名',
- 'expect' => '期望',
- 'height' => '身高',
- 'age' => '生日',
- 'weixin' => '微信号',
- 'qq' => 'QQ号',
- ];
- }
- }
|