Request.php 865 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Http\Requests;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. abstract class Request 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. return $this->getRules();
  23. }
  24. public function getRules()
  25. {
  26. list(, $action) = explode('@', $this->route()->getActionName());
  27. $ruleMethodName = 'get' . ucfirst($action) . 'Rules';
  28. if(method_exists($this, $ruleMethodName)){
  29. $rules = $this->$ruleMethodName();
  30. if(is_array($rules)){
  31. return $rules;
  32. }
  33. }
  34. return [];
  35. }
  36. }