CreateOrUpdateRequest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Http\Requests\API\User;
  3. use App\Http\Requests\RuleHelper;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. class CreateOrUpdateRequest extends FormRequest
  6. {
  7. use RuleHelper;
  8. /**
  9. * Determine if the user is authorized to make this request.
  10. */
  11. public function authorize(): bool
  12. {
  13. return true;
  14. }
  15. /**
  16. * Get the validation rules that apply to the request.
  17. *
  18. * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
  19. */
  20. public function rules(): array
  21. {
  22. return [
  23. 'name' => 'required|max:100',
  24. 'email'=> 'required|email|unique:users',
  25. 'username'=>'required|max:30|unique:users',
  26. 'password' => 'required|min:6|regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{6,}$/', // 至少6位,包含大小写字母和数字
  27. 'confirm_password' => 'required|same:password', // 与password字段相同
  28. 'phone'=>'nullable|regex:/^\d{10}$/',
  29. 'gender'=>'nullable|in:1,0',
  30. 'address'=>'nullable|max:255',
  31. 'company_id'=>'required|exists:company,id',
  32. 'department_id'=>'required|exists:department,id',
  33. 'role_id'=>'required|exists:roles,id',
  34. ];
  35. }
  36. }