ProfilerRequest.php 1.8 KB

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