UpdateUserRequest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Http\Requests\System;
  3. use App\Http\Models\Role;
  4. use App\Http\Requests\Request;
  5. use Illuminate\Validation\Rule;
  6. use Illuminate\Database\Query\Builder;
  7. class UpdateUserRequest extends Request
  8. {
  9. /**
  10. * Determine if the user is authorized to make this request.
  11. *
  12. * @return bool
  13. */
  14. public function authorize()
  15. {
  16. return true;
  17. }
  18. /**
  19. * Get the validation rules that apply to the request.
  20. *
  21. * @return array
  22. */
  23. public function rules()
  24. {
  25. $addition = [];
  26. // if ($this->input('role_id') == Role::TYPE_CUSTOMER) {
  27. $addition['site_ids'] = 'nullable|array';
  28. // }
  29. return [
  30. 'nickname' => 'required',
  31. 'username' => [
  32. 'required',
  33. 'min:3',
  34. 'max:15',
  35. Rule::unique('users')->where(function (Builder $query) {
  36. return $query->where('deleted_at', null);
  37. })->ignore($this->route('id'))
  38. ],
  39. 'password' => 'nullable|min:5|max:15',
  40. 'phone' => [
  41. 'nullable',
  42. Rule::unique('users')->where(function (Builder $query) {
  43. return $query->where('deleted_at', null);
  44. })->ignore($this->route('id'))
  45. ],
  46. 'entry_time' => 'nullable',
  47. 'telephone' => 'nullable',
  48. 'email' => 'nullable',
  49. 'qq' => 'nullable',
  50. 'role_id' => 'required|numeric',
  51. 'status' => 'boolean',
  52. ] + $addition;
  53. }
  54. public function attributes()
  55. {
  56. return [
  57. 'nickname' => '昵称',
  58. 'username' => '用户名',
  59. 'phone' => '手机号',
  60. 'password' => '密码',
  61. 'email' => '邮箱',
  62. 'qq' => 'qq号',
  63. 'role_id' => '角色',
  64. 'status' => '状态',
  65. 'sort' => '排序',
  66. 'site_id' => '站点',
  67. 'telephone' => '座机',
  68. ];
  69. }
  70. }