本文整理汇总了PHP中Illuminate\Support\Facades\Validator::extend方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::extend方法的具体用法?PHP Validator::extend怎么用?PHP Validator::extend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Validator
的用法示例。
在下文中一共展示了Validator::extend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: function
function __construct()
{
Parent::__construct();
Validator::extend('total', function ($attribute, $value, $parameters, $validator) {
$value != 100 ? $check = false : ($check = true);
return $check;
});
}
示例2: 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);
});
}
示例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], "Max cannot be less than min");
});
}
示例4: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Validator::extend('text', function ($attribute, $value) {
//Alpha dash with space,dot and newline
return preg_match('/^[\\n\\. \\pL\\pM\\pN_-]+$/u', $value);
});
}
示例5: boot
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//Used to check if surf start is before end. Can't surf time travel :)
Validator::extend('surftime', function ($attribute, $value, $parameters, $validator) {
return $value >= $parameters[0];
});
}
示例6: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Validator::extend('hashed', function ($attribute, $value, $parameters) {
// If we're already logged in
if (Auth::check()) {
$user = Auth::user();
} else {
// Otherwise, try to get the username from form input
$user = User::where('name', Input::get('name'))->get();
if (!$user->count()) {
return false;
}
$user = $user[0];
}
if (Hash::check($value, $user->password)) {
return true;
}
return false;
});
Validator::extend('time', function ($attribute, $value, $parameters) {
$value = trim($value);
// Check against 12 hour time (with AM/PM) or 24 hour time
$twelve = date_parse_from_format('h:i a', $value);
$twentyfour = date_parse_from_format('H:i', $value);
if ($twelve['error_count'] === 0 || $twentyfour['error_count'] === 0) {
return true;
}
return false;
});
}
示例7: registerValidationRules
/**
* Registers validation rules
*/
protected function registerValidationRules()
{
$rules = ['not_reserved_name' => 'NotReservedName', 'date_mysql' => 'DateMysql'];
foreach ($rules as $name => $rule) {
Validator::extend($name, 'Reactor\\Support\\Validation\\FormValidator@validate' . $rule);
}
}
示例8: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Validator::extend('strp', function ($attribute, $value, $parameters) {
// compare the entered password with what the database has, e.g. validates the current password
return strip_tags($value);
});
}
示例9: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Validator::extend('check_auth_user_password', function ($attribute, $value, $parameters, $validator) {
return Hash::check($value, Auth::user()->password);
});
// Make sure client email is not used by another client of current user
Validator::extend('email_not_used_by_another_user_client', function ($attribute, $value, $parameters, $validator) {
if (Client::where('user_id', Auth::user()->id)->where('email', $value)->count()) {
return false;
}
return true;
});
// Make sure client phone number is not user by another client of current user
Validator::extend('phone_number_not_used_by_another_user_client', function ($attribute, $value, $parameters, $validator) {
if (Client::where('user_id', Auth::user()->id)->where('phone_number', $value)->count()) {
return false;
}
return true;
});
Validator::extend('not_exists', function ($attribute, $value, $parameters, $validator) {
return !DB::table($parameters[0])->where($parameters[1], $value)->count();
});
Validator::extend('is_not_in_auth_user_products', function ($attribute, $value, $parameters, $validator) {
return !DB::table('products')->where('user_id', \Auth::user()->id)->where('code', $value)->count();
});
}
示例10: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// Add some custom validation rules
Validator::extend('valid_path', function ($attribute, $value, $parameters, $validator) {
return is_dir($value) && is_readable($value);
});
}
示例11: extendValidators
public function extendValidators()
{
// Function to call the Uuid validator
Validator::extend('currency_code', function ($attribute, $value) {
$currency = new CurrencyService();
return $currency->checkCurrency($value);
}, 'Currency code is incorrect');
}
示例12: function
function __construct()
{
Validator::extend('activity_file', function ($attribute, $value, $parameters, $validator) {
$mimes = ['application/excel', 'application/vnd.ms-excel', 'application/msexcel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'text/csv'];
$fileMime = $value->getClientMimeType();
return in_array($fileMime, $mimes);
});
}
示例13: boot
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
Validator::extend('at_least_one_admin', 'App\\Validators\\RoleValidators@atLeastOneAdmin');
Validator::extend('own_admin_role', 'App\\Validators\\RoleValidators@ownAdminRole');
Validator::resolver(function ($translator, $data, $rules, $messages) {
return new Validation($translator, $data, $rules, $messages);
});
}
示例14: boot
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
$this->loadTranslationsFrom(__DIR__ . '/../resources/lang/', 'calendar-events');
$this->loadViewsFrom(__DIR__ . '/../resources/views/', 'calendar-events');
$this->publishes([__DIR__ . '/../database/migrations/' => database_path('migrations/'), __DIR__ . '/../config/' => config_path('calendar-events/'), __DIR__ . '/../resources/lang/' => base_path('resources/lang/'), __DIR__ . '/../resources/views/' => base_path('resources/vendor/calendar-events/'), __DIR__ . '/../public/js/' => public_path('/js/')]);
Validator::extend('time', '\\Todstoychev\\CalendarEvents\\Validator\\CalendarEventsValidator@validateTime');
Validator::extend('dates_array', '\\Todstoychev\\CalendarEvents\\Validator\\CalendarEventsValidator@validateDatesArray');
}
示例15: 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');
}