WorkerRequest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Http\Requests;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. use Illuminate\Support\Arr;
  5. class WorkerRequest extends FormRequest
  6. {
  7. /**
  8. * Determine if the user is authorized to make this request.
  9. *
  10. * @return bool
  11. */
  12. public function authorize()
  13. {
  14. return true;
  15. }
  16. /**
  17. * Get the validation rules that apply to the request.
  18. *
  19. * @return array
  20. */
  21. public function rules()
  22. {
  23. $id = (int) optional($this->route('worker'))->id;
  24. $rules = [
  25. 'job_number'=>'required|max:6|min:3|unique:admin_users,job_number,'.$id,
  26. 'account'=>'required|unique:admin_users,account,'.$id,
  27. 'name'=>'required',
  28. 'phone'=>'required',
  29. 'area_id'=>'required',
  30. 'status'=>'required'
  31. ];
  32. if ($this->isMethod('put')) {
  33. $rules = Arr::only($rules, $this->keys());
  34. }
  35. return $rules;
  36. }
  37. public function attributes()
  38. {
  39. return [
  40. 'job_number' => '工号',
  41. 'account' => '账号',
  42. 'name' => '姓名',
  43. 'phone' => '电话',
  44. 'area_id' => '负责区域'
  45. ]; // TODO: Change the autogenerated stub
  46. }
  47. }