本文整理汇总了PHP中Illuminate\Support\Facades\Validator::replacer方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::replacer方法的具体用法?PHP Validator::replacer怎么用?PHP Validator::replacer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Validator
的用法示例。
在下文中一共展示了Validator::replacer方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerValidators
private function registerValidators()
{
Validator::extend('extensions', function ($attribute, $value, $parameters) {
return in_array($value->getClientOriginalExtension(), $parameters);
});
Validator::replacer('extensions', function ($message, $attribute, $rule, $parameters) {
return str_replace([':attribute', ':values'], [$attribute, implode(',', $parameters)], $message);
});
}
示例2: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Validator::extend('greater_than_field', function ($attribute, $value, $parameters, $validator) {
$min_field = $parameters[0];
$data = $validator->getData();
$min_value = $data[$min_field];
return $value >= $min_value;
});
Validator::replacer('greater_than_field', function ($message, $attribute, $rule, $parameters) {
return str_replace(':field', $parameters[0], "Max cannot be less than min");
});
}
示例3: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
Validator::extend('greater_than_field', function ($attribute, $value, $parameters, $validator) {
$min_field = $parameters[0];
$data = $validator->getData();
$min_value = $data[$min_field];
return $value > $min_value;
});
Validator::replacer('greater_than_field', function ($message, $attribute, $rule, $parameters) {
return str_replace(':field', $parameters[0], "Check that min members per team is less than max members per team!");
});
}
示例4: boot
public function boot()
{
$this->loadTranslationsFrom(__DIR__ . '/lang', 'laravel-profane');
$this->publishes([__DIR__ . '/lang' => resource_path('lang/vendor/laravel-profane')]);
Validator::extend('profane', 'LaravelProfane\\ProfaneValidator@validate', Lang::get('laravel-profane::validation.profane'));
Validator::replacer('profane', function ($message, $attribute, $rule, $parameters) {
return str_replace(':attribute', $attribute, $message);
});
}
示例5: boot
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
Validator::extend('current_password', function ($attribute, $value, $parameters, $validator) {
return Hash::check($value, Auth::user()->password);
});
Validator::replacer('current_password', function ($message, $attribute, $rule, $parameters) {
return str_replace($message, $message, 'Incorrect current password.');
});
}
示例6: boot
public function boot()
{
Validator::extend('jalali', JalaliValidator::class . '@validateJalali');
Validator::extend('jalali_after', JalaliValidator::class . '@validateAfter');
Validator::extend('jalali_before', JalaliValidator::class . '@validateBefore');
Validator::replacer('jalali', JalaliValidator::class . '@replaceJalali');
Validator::replacer('jalali_after', JalaliValidator::class . '@replaceAfterOrBefore');
Validator::replacer('jalali_before', JalaliValidator::class . '@replaceAfterOrBefore');
}
示例7: registerJDateTimeRules
protected function registerJDateTimeRules()
{
Validator::extend('jdatetime', JalaliValidator::class . '@validateJDateTime');
Validator::extend('jdatetime_after', JalaliValidator::class . '@validateJDateTimeAfter');
Validator::extend('jdatetime_before', JalaliValidator::class . '@validateJDateTimeBefore');
Validator::replacer('jdatetime', JalaliValidator::class . '@replaceJalali');
Validator::replacer('jdatetime_after', JalaliValidator::class . '@replaceAfterOrBefore');
Validator::replacer('jdatetime_before', JalaliValidator::class . '@replaceAfterOrBefore');
}
示例8: boot
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
Validator::extend('cnp', function ($attribute, $value, $parameters) {
return Cnp::valid($value);
});
Validator::replacer('cnp', function ($message, $attribute, $rule, $parameters) {
$message = "Cnp-ul introdus nu este corect!";
return $message;
});
}
示例9: boot
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
$this->loadTranslationsFrom(__DIR__ . '/../../resources/lang', 'instance-validator');
$this->publishes([__DIR__ . '/../../resources/lang' => resource_path('lang/vendor/instance-validator')]);
Validator::extend('instance_of', function ($attribute, $value, $parameters, $validator) {
if (count($parameters) != 1) {
throw new Exception("The 'instance_of' validator requires a single type to be specified.");
}
return $value instanceof $parameters[0];
});
Validator::replacer('instance_of', function ($message, $attribute, $rule, $parameters) {
$msg = Lang::trans('instance-validator::' . $message);
$msg = str_replace([':attribute', ':type'], [$attribute, $parameters[0]], $msg);
return $msg;
});
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Validator::extend('collection_of', function ($attribute, $value, $parameters, $validator) {
if (count($parameters) != 1) {
throw new Exception("The 'collection_of' validator requires a single type to be specified.");
}
$isCollection = $value instanceof Collection;
$itemIsCorrectType = $value[0] instanceof $parameters[0] || strtolower($parameters[0]) === 'string' && is_string($value[0]);
return $isCollection && $itemIsCorrectType;
});
Validator::replacer('collection_of', function ($message, $attribute, $rule, $parameters) {
$msg = Lang::trans('instance-validator::' . $message);
$msg = str_replace([':attribute', ':type'], [$attribute, $parameters[0]], $msg);
return $msg;
});
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Validator::extend('paginator_of', function ($attribute, $value, $parameters, $validator) {
if (count($parameters) != 1) {
throw new Exception("The 'paginator_of' validator requires a single type to be specified.");
}
if (!$value instanceof LengthAwarePaginator) {
throw new Exception("The 'paginator_of' validator requires a LengthAwarePaginator instance.");
}
$itemIsCorrectType = $value->items()[0] instanceof $parameters[0] || strtolower($parameters[0]) === 'string' && is_string($value->items()[0]);
return $itemIsCorrectType;
});
Validator::replacer('paginator_of', function ($message, $attribute, $rule, $parameters) {
$msg = Lang::trans('instance-validator::' . $message);
$msg = str_replace([':attribute', ':type'], [$attribute, $parameters[0]], $msg);
return $msg;
});
}
示例10: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Validator::extend('greater_than_field', function ($attribute, $value, $parameters, $validator) {
$other = Input::get($parameters[0]);
return isset($other) and intval($value) >= intval($other);
});
Validator::replacer('greater_than_field', function ($message, $attribute, $rule, $parameters) {
return str_replace(':field', $parameters[0], $message);
});
Validator::extend('is_after_date', function ($attribute, $value, $parameters, $validator) {
$other = Input::get($parameters[0]);
return isset($other) and new DateTime($value) >= new DateTime($other);
});
Validator::replacer('is_after_date', function ($message, $attribute, $rule, $parameters) {
return str_replace(':field', $parameters[0], $message);
});
}
示例11: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot(Router $router)
{
if (!$this->app->routesAreCached()) {
require __DIR__ . '/../Http/routes.php';
}
$router->middleware('admin', \Philsquare\LaraManager\Http\Middleware\AdminMiddleware::class);
$router->middleware('guest.admin', \Philsquare\LaraManager\Http\Middleware\RedirectIfAuthenticated::class);
$this->loadViewsFrom(__DIR__ . '/../../../views', 'laramanager');
$this->assetsToPublish();
$this->setViewComposers();
$this->loadTranslationsFrom(__DIR__ . '/../../../lang', 'laramanager');
Validator::extend('unique_filename', 'Philsquare\\LaraManager\\Validators\\UniqueFilenameValidator@validate');
Validator::extend('model_must_exist', 'Philsquare\\LaraManager\\Validators\\ModelMustExistValidator@validate');
Validator::replacer('model_must_exist', function ($message, $attribute, $rule, $parameters) {
return trans('laramanager::validation.model_must_exist');
});
}
示例12: height
protected function height()
{
$this->app->before(function () {
Validator::extend('height', 'Moxar\\Validation\\Rules\\Image@height');
Validator::replacer('height', function ($message, $attribute, $rule, $parameters) {
return $message = str_replace(':value', $parameters[0], $message);
});
});
}
示例13: extendValidator
/**
* add custom validation rules
*/
protected function extendValidator()
{
Validator::extend('gt', function ($attribute, $value, $parameters, $validator) {
return $value > $parameters[0];
});
Validator::extend('gte', function ($attribute, $value, $parameters, $validator) {
return $value >= $parameters[0];
});
Validator::extend('lt', function ($attribute, $value, $parameters, $validator) {
return $value < $parameters[0];
});
Validator::extend('lte', function ($attribute, $value, $parameters, $validator) {
return $value <= $parameters[0];
});
Validator::replacer('gt', function ($message, $attribute, $rule, $parameters) {
return str_replace([':attribute', ':gt'], [$attribute, $parameters[0]], $message);
});
Validator::replacer('gte', function ($message, $attribute, $rule, $parameters) {
return str_replace([':attribute', ':gte'], [$attribute, $parameters[0]], $message);
});
Validator::replacer('lt', function ($message, $attribute, $rule, $parameters) {
return str_replace([':attribute', ':lt'], [$attribute, $parameters[0]], $message);
});
Validator::replacer('lte', function ($message, $attribute, $rule, $parameters) {
return str_replace([':attribute', ':lte'], [$attribute, $parameters[0]], $message);
});
}
示例14: function
Validator::replacer('positive', function ($message, $attribute, $rule, $parameters) {
return sprintf('The %s must contain a positive number', $attribute);
});
/*
* Validates the submitted value if it is greater than the validation parameter.
*/
Validator::extend('greater_than', 'Stevebauman\\Maintenance\\Validators\\GreaterThanNumberValidator@validateGreaterThan');
Validator::replacer('greater_than', function ($message, $attribute, $rule, $parameters) {
return sprintf('The %s must be greater than %s', $attribute, $parameters[0]);
});
/*
* Validates the submitted value if its less than the validation parameter.
*/
Validator::extend('less_than', 'Stevebauman\\Maintenance\\Validators\\LessThanNumberValidator@validateLessThan');
Validator::replacer('less_than', function ($message, $attribute, $rule, $parameters) {
return sprintf('The %s must be less than %s', $attribute, $parameters[0]);
});
/*
* Validates that the current user only has one session open
*/
Validator::extend('session_start', 'Stevebauman\\Maintenance\\Validators\\WorkOrder\\SessionStartValidator@validateSessionStart');
Validator::replacer('session_start', function () {
return "You already have an open session, you must close it to begin a new one.";
});
/*
* Validates that the current user can only close their session once
*/
Validator::extend('session_end', 'Stevebauman\\Maintenance\\Validators\\WorkOrder\\SessionEndValidator@validateSessionEnd');
Validator::replacer('session_end', function () {
return "This session has already ended. You must create a new session.";
});