I'm using the docs at http://four.laravel.com/docs/validation under 'Registering A Custom Validator Resolver' but I'm getting an exception thrown
class CustomValidator extends Illuminate\Validation\Validator {
public function validateFoo($attribute, $value, $parameters)
{
return $value == 'foo';
}
}
In my service provider
Validator::resolver(function($translator, $data, $rules, $messages)
{
return new CustomValidator($translator, $data, $rules, $messages);
});
But I get the following exception
Error: Call to undefined method Illuminate\Support\Facades\Validator::resolver() in /vagrant/bootstrap/compiled.php line 5299
Paste your service provider.
OK, this is the full provider
<?php
use Illuminate\Support\ServiceProvider;
class PlatformServiceProvider extends ServiceProvider
{
public function register()
{
App::bind('Repositories\IAccountRepository', 'Repositories\AccountRepository');
App::bind('Repositories\ICampaignRepository', 'Repositories\CampaignRepository');
App::bind('Repositories\IMailingListImportRepository', 'Repositories\MailingListImportRepository');
App::bind('Repositories\IMailingListRepository', 'Repositories\MailingListRepository');
App::bind('Repositories\IPersonRepository', 'Repositories\PersonRepository');
App::bind('Repositories\IUserRepository', 'Repositories\UserRepository');
App::bind(
'S3StorageService',
function () {
return new S3StorageService(
Config::get('s3.key'),
Config::get('s3.secret'),
Config::get('s3.bucket')
);
}
);
App::bind(
'LMongo\Connection',
function () {
return LMongo::connection();
}
);
Route::filter(
'role',
function ($group) {
if (Auth::guest()) {
return Redirect::to('login');
}
$user = Auth::user();
if (!isset($user)) {
return Redirect::to('login');
}
// Only allow super if super
if ($group == User::$user_type_super && $user->user_type != User::$user_type_super) {
return Redirect::to('login');
}
// Only allow admin if not user
if ($group == User::$user_type_admin && $user->user_type == User::$user_type_user) {
return Redirect::to('login');
}
}
);
Request::setTrustedProxies(array('127.0.0.1'));
$this->app['validation.presence'] = $this->app->share(
function ($app) {
return new MongoPresenceVerifier($app['db']);
}
);
Validator::resolver(function($translator, $data, $rules, $messages)
{
return new \Services\PlatformValidator($translator, $data, $rules, $messages);
});
}
}
Move your Route::filters and the Validator::resolve stuff into the boot
method. Register is strictly for registering / binding. Nothing else
should be done.
Yeah, that fixed it. Thanks for the quick response
Most helpful comment
Move your Route::filters and the Validator::resolve stuff into the boot
method. Register is strictly for registering / binding. Nothing else
should be done.