Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\JsonApi\v1\Comments;
  4.  
  5. use CloudCreativity\LaravelJsonApi\Rules\HasOne;
  6. use CloudCreativity\LaravelJsonApi\Validation\AbstractValidators;
  7.  
  8. class Validators extends AbstractValidators
  9. {
  10.  
  11. /**
  12. * The include paths a client is allowed to request.
  13. *
  14. * @var string[]|null
  15. * the allowed paths, an empty array for none allowed, or null to allow all paths.
  16. */
  17. protected $allowedIncludePaths = [
  18. 'commentator', 'post', 'post.author'
  19. ];
  20.  
  21. /**
  22. * The sort field names a client is allowed send.
  23. *
  24. * @var string[]|null
  25. * the allowed fields, an empty array for none allowed, or null to allow all fields.
  26. */
  27. protected $allowedSortParameters = [
  28. 'body', 'created_at'
  29. ];
  30.  
  31. /**
  32. * The filters a client is allowed send.
  33. *
  34. * @var string[]|null
  35. * the allowed filters, an empty array for none allowed, or null to allow all.
  36. */
  37. protected $allowedFilteringParameters = [
  38. 'search', 'body'
  39. ];
  40.  
  41. /**
  42. * Get resource validation rules.
  43. *
  44. * @param mixed|null $record
  45. * the record being updated, or null if creating a resource.
  46. * @return mixed
  47. */
  48. protected function rules($record = null): array
  49. {
  50. return [
  51. 'commentator' => [
  52. 'required',
  53. new HasOne('users')
  54. ],
  55. 'post' => [
  56. 'required',
  57. new HasOne('posts')
  58. ],
  59. 'body' => 'required|string|min:3'
  60. ];
  61. }
  62.  
  63. /**
  64. * Get query parameter validation rules.
  65. *
  66. * @return array
  67. */
  68. protected function queryRules(): array
  69. {
  70. return [
  71. 'filter.search' => 'filled|string',
  72. 'filter.body' => 'filled|string'
  73. ];
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement