1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace App\Validators;
- use Illuminate\Foundation\Http\FormRequest;
- class BaseValidatorRequest extends FormRequest
- {
- public function authorize()
- {
- return true;
- }
- /**
- * Get the validation rules that apply to the request.
- *
- * @return array
- */
- public function rules()
- {
- return $this->getData();
- }
- public function messages()
- {
- return $this->getData('messages');
- }
- private function getData($type = 'rules')
- {
- $action=$this->route()->getAction();
- list($controller, $method)=explode('@', $action['controller']);
- if (!method_exists($this, $method)) {
- return [];
- }
- return $this->$method()[$type]?:[];
- }
- }
|