Skip to content
This repository was archived by the owner on Sep 13, 2024. It is now read-only.

Commit 00337fe

Browse files
author
VladimirBerdnik
committed
Resolve "Presence verifier has not been set." issue
1 parent d1eca31 commit 00337fe

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

CHANGES.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Changes History
22

3+
1.0.6
4+
-----
5+
Resolve "Presence verifier has not been set." issue for **exists** and **in** rules
6+
37
1.0.5
48
-----
5-
Add ability to use custom declared validation rules
9+
Add ability to use custom declared validation rules
610

711
1.0.4
812
-----
9-
Add 'sometimes' rule modifier
13+
Add 'sometimes' rule modifier
1014

1115
1.0.3
1216
-----

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ Add the FluentValidationServiceProvider in ``config/app.php``:
5757
*Note:* You can omit service provider registration, but then you must call
5858
*->toString()* or *->toArray()* on each builder.
5959
If service provider is registered, manual casting of rule to string or array
60-
is not necessary.
60+
is not necessary and default Laravel's *Illuminate\Validation\ValidationServiceProvider::class*
61+
can be removed from *'providers'* array.
6162

6263

6364
## Available classes

src/FluentValidationServiceProvider.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,28 @@
22

33
namespace Saritasa\Laravel\Validation;
44

5-
use Illuminate\Support\ServiceProvider;
5+
use Illuminate\Validation\ValidationServiceProvider;
66
use Illuminate\Contracts\Validation\Factory as IValidatorFactory;
77

88
/**
99
* Service provider substitutes default Laravel's validation factory
1010
* @see FluentValidatorFactory
1111
*/
12-
class FluentValidationServiceProvider extends ServiceProvider
12+
class FluentValidationServiceProvider extends ValidationServiceProvider
1313
{
14-
public function boot()
14+
protected function registerValidationFactory()
1515
{
16-
$this->app->bind(IValidatorFactory::class, FluentValidatorFactory::class);
16+
$this->app->singleton('validator', function ($app) {
17+
$validator = new FluentValidatorFactory($app['translator'], $app);
18+
19+
// The validation presence verifier is responsible for determining the existence of
20+
// values in a given data collection which is typically a relational database or
21+
// other persistent data stores. It is used to check for "uniqueness" as well.
22+
if (isset($app['db'], $app['validation.presence'])) {
23+
$validator->setPresenceVerifier($app['validation.presence']);
24+
}
25+
26+
return $validator;
27+
});
1728
}
1829
}

0 commit comments

Comments
 (0)