Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\JsonApi\v1\Comments;
- use CloudCreativity\LaravelJsonApi\Rules\HasOne;
- use CloudCreativity\LaravelJsonApi\Validation\AbstractValidators;
- class Validators extends AbstractValidators
- {
- /**
- * The include paths a client is allowed to request.
- *
- * @var string[]|null
- * the allowed paths, an empty array for none allowed, or null to allow all paths.
- */
- protected $allowedIncludePaths = [
- 'commentator', 'post', 'post.author'
- ];
- /**
- * The sort field names a client is allowed send.
- *
- * @var string[]|null
- * the allowed fields, an empty array for none allowed, or null to allow all fields.
- */
- protected $allowedSortParameters = [
- 'body', 'created_at'
- ];
- /**
- * The filters a client is allowed send.
- *
- * @var string[]|null
- * the allowed filters, an empty array for none allowed, or null to allow all.
- */
- protected $allowedFilteringParameters = [
- 'search', 'body'
- ];
- /**
- * Get resource validation rules.
- *
- * @param mixed|null $record
- * the record being updated, or null if creating a resource.
- * @return mixed
- */
- protected function rules($record = null): array
- {
- return [
- 'commentator' => [
- 'required',
- new HasOne('users')
- ],
- 'post' => [
- 'required',
- new HasOne('posts')
- ],
- 'body' => 'required|string|min:3'
- ];
- }
- /**
- * Get query parameter validation rules.
- *
- * @return array
- */
- protected function queryRules(): array
- {
- return [
- 'filter.search' => 'filled|string',
- 'filter.body' => 'filled|string'
- ];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement