BaseValidatorRequest.php 761 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Validators;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. class BaseValidatorRequest extends FormRequest
  5. {
  6. public function authorize()
  7. {
  8. return true;
  9. }
  10. /**
  11. * Get the validation rules that apply to the request.
  12. *
  13. * @return array
  14. */
  15. public function rules()
  16. {
  17. return $this->getData();
  18. }
  19. public function messages()
  20. {
  21. return $this->getData('messages');
  22. }
  23. private function getData($type = 'rules')
  24. {
  25. $action=$this->route()->getAction();
  26. list($controller, $method)=explode('@', $action['controller']);
  27. if (!method_exists($this, $method)) {
  28. return [];
  29. }
  30. return $this->$method()[$type]?:[];
  31. }
  32. }