Skip to content

Commit

Permalink
Updates based on the review
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravan Scafi committed Sep 20, 2018
1 parent e4c061f commit cf93294
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/MongolidServiceProvider.php
Expand Up @@ -203,15 +203,12 @@ private function createValidationRules(): void
{
$validator = $this->app->make(Factory::class);

// Define "mongolid_unique" rule
$validator->extend('mongolid_unique', Rules::class.'@unique');
$validator->replacer('mongolid_unique', Rules::class.'@message');

// Define "mongolid_exists" rule
$validator->extend('mongolid_exists', Rules::class.'@exists');
$validator->replacer('mongolid_exists', Rules::class.'@message');

// Define "object_id" rule
$validator->extend('object_id', Rules::class.'@objectId');
$validator->replacer('object_id', Rules::class.'@objectIdMessage');
}
Expand Down
25 changes: 23 additions & 2 deletions src/Validation/Rules.php
Expand Up @@ -21,7 +21,19 @@ public function __construct(Pool $pool)
/**
* mongolid_unique:collection,field?,except?,idField?
*
* @see https://laravel.com/docs/5.5/validation#rule-unique
* @example Using attribute name as query field
* 'email' => mongolid_unique:users
*
* @example Using other query field
* 'email' => mongolid_unique:users,user_email
*
* @example Excluding itself from verification
* 'email' => mongolid_unique:users,email,5ba3bc0836e5eb03f12a3c31
*
* @example Excluding itself from verification using other field for Id
* 'email' => mongolid_unique:users,email,5ba3bc0836e5eb03f12a3c31,user_id
*
* @see https://laravel.com/docs/5.6/validation#rule-unique
*/
public function unique(string $attribute, $value, array $parameters)
{
Expand All @@ -42,7 +54,13 @@ public function unique(string $attribute, $value, array $parameters)
/**
* mongolid_exists:collection,field?
*
* @see https://laravel.com/docs/5.5/validation#rule-exists
* @example Using attribute name as query field
* 'email' => mongolid_exists:users
*
* @example Using other query field
* 'email' => mongolid_exists:users,user_email
*
* @see https://laravel.com/docs/5.6/validation#rule-exists
*/
public function exists(string $attribute, $value, array $parameters)
{
Expand Down Expand Up @@ -72,6 +90,9 @@ public function message(string $message, string $attribute, string $rule): strin
* Given attribute should be an ObjectId
* object_id
*
* @example Using attribute name as query field
* 'product_id' => object_id
*
* @see ObjectId
*/
public function objectId(string $attribute, $value)
Expand Down

0 comments on commit cf93294

Please sign in to comment.