AdminUpdateRequest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Http\Requests\API\User;
  3. use App\Http\Requests\RuleHelper;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Support\Facades\Auth;
  6. use Illuminate\Support\Facades\Hash;
  7. class AdminUpdateRequest extends FormRequest
  8. {
  9. use RuleHelper;
  10. /**
  11. * Determine if the user is authorized to make this request.
  12. */
  13. public function authorize(): bool
  14. {
  15. return true;
  16. }
  17. /**
  18. * Get the validation rules that apply to the request.
  19. *
  20. * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
  21. */
  22. public function rules(): array
  23. {
  24. return [
  25. 'name' => 'max:100',
  26. 'email'=> 'email|unique:users',
  27. 'username'=>'max:30|unique:users',
  28. 'password' => 'min:6|regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{6,}$/', // 至少6位,包含大小写字母和数字,At least 6 digits, including upper and lower case letters and numbers
  29. 'auth_password' => [
  30. 'required',
  31. function ($attribute, $value, $fail) {
  32. if (!Hash::check($value, Auth::user()->password)) {
  33. $fail("Wrong security authentication password!");
  34. }
  35. }
  36. ],
  37. 'phone'=>'nullable',
  38. 'gender'=>'in:1,0',
  39. 'address'=>'max:255',
  40. 'company_id'=>'exists:company,id',
  41. 'department_id'=>'exists:department,id',
  42. 'role_id'=>'exists:roles,id',
  43. ];
  44. }
  45. }