PermissionSaveRequest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Http\Requests\System;
  3. use App\Http\Requests\Request;
  4. use Illuminate\Validation\Rule;
  5. class PermissionSaveRequest extends Request
  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. if (!$this->ajax()) {
  24. return [];
  25. }
  26. $addition = [];
  27. if ($this->route('id') == 0) { //添加时验证
  28. $addition['parent_id'] = 'required|numeric';
  29. }
  30. return [
  31. 'title' => 'required',
  32. 'rule' => 'nullable',
  33. 'icon' => 'nullable',
  34. 'type' => ['required', Rule::in([1, 2])],
  35. 'sort' => 'required|numeric',
  36. ] + $addition;
  37. }
  38. public function attributes()
  39. {
  40. return [
  41. 'title' => '权限名称',
  42. 'type' => '权限类型',
  43. 'rule' => '权限标识',
  44. 'icon' => '图标',
  45. 'parent_id' => '父ID',
  46. 'sort' => '排序',
  47. ];
  48. }
  49. }