UserUpdateRequest.php 952 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Http\Requests;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. class UserUpdateRequest extends FormRequest
  5. {
  6. /**
  7. * Determine if the user is authorized to make this request.
  8. *
  9. * @return bool
  10. */
  11. public function authorize()
  12. {
  13. return true;
  14. }
  15. /**
  16. * Get the validation rules that apply to the request.
  17. *
  18. * @return array
  19. */
  20. public function rules()
  21. {
  22. $reture = [
  23. 'email' => 'required|unique:users,email,'.$this->get('id').',id|email',
  24. 'phone' => 'required|numeric|regex:/^1[34578][0-9]{9}$/|unique:users,phone,'.$this->get('id').',id',
  25. 'username' => 'required|min:4|max:14|unique:users,username,'.$this->get('id').',id',
  26. ];
  27. if ($this->get('password') || $this->get('password_confirmation')){
  28. $reture['password'] = 'required|confirmed|min:6|max:14';
  29. }
  30. return $reture;
  31. }
  32. }