本文整理汇总了PHP中Validator::extend方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::extend方法的具体用法?PHP Validator::extend怎么用?PHP Validator::extend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validator
的用法示例。
在下文中一共展示了Validator::extend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
public function boot()
{
$this->loadViewsFrom(realpath(__DIR__ . '/../views'), 'maikblog');
$this->publishes([realpath(__DIR__ . '/../views') => base_path('resources/views/vendor/maikblog')]);
$this->setupRoutes($this->app->router);
// this for conig
$this->publishes([__DIR__ . '/config/maikblog.php' => config_path('maikblog.php')], 'config');
//this for migrations
$this->publishes([__DIR__ . '/database/migrations/' => database_path('migrations')], 'migrations');
//this for css and js
$this->publishes([realpath(__DIR__ . '/../assets') => public_path('maiklez/maikblog')], 'public');
\Validator::extend('tag_rule', function ($attribute, $value, $parameters) {
$tags = explode(',', $value);
// remove empty items from array
$tags = array_filter($tags);
// trim all the items in array
$tags = array_map('trim', $tags);
\Debugbar::info($tags);
foreach ($tags as $tag) {
if ($tag === "") {
return false;
}
}
return true;
});
\Validator::replacer('tag_rule', function ($message, $attribute, $rule, $parameters) {
return str_replace("no white spaces are allow");
});
}
示例2: validate
public function validate($input_arr = array())
{
$this->validate_errors = array();
//Log::info('in database'.print_r($input_arr, true));
Validator::extend('in_database', function ($attribute, $value, $parameters) use($input_arr) {
//Log::info('in database'.print_r($parameters, true));
if ($attribute == 'host') {
return Check::where('check_id', '!=', isset($input_arr['check_id']) && ($c = $input_arr['check_id']) ? $c : 0)->where('user_id', $input_arr['user_id'])->where('type', $input_arr['type'])->where('host', $value)->count() == 0;
} else {
return Check::where('check_id', '!=', isset($input_arr['check_id']) && ($c = $input_arr['check_id']) ? $c : 0)->where('user_id', $input_arr['user_id'])->where('type', $input_arr['type'])->where('url', $input_arr['type'] == 'https' ? str_replace('http://', 'https://', $value) : $value)->count() == 0;
}
});
$rules = $this->rules[$this->use_rules];
if (isset($input_arr['edit_options']) && $input_arr['edit_options']) {
$rules['options'] = 'json_decode';
} else {
$rules['phrases'] = 'json_encode';
$rules['post_body'] = 'json_encode';
}
$attributes = array('url' => $input_arr['url'], 'type' => $input_arr['type'], 'action' => $input_arr['action']);
$validator = Validator::make($input_arr, $rules);
//$validator->setAttributeNames($attributes);
if ($validator->fails()) {
$this->set_custom_attributes($validator, $attributes);
//$this->validate_errors = $validator->messages()->all();
return false;
} else {
return true;
}
}
示例3: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
\Validator::extend('current_password', function ($attribute, $value, $parameters, $validator) {
return \Hash::check($value, \Auth::user()->password);
});
}
开发者ID:elNapoli,项目名称:iCnca7CrTNYXRF4oxPSidusv17MoVk7CEAhNGFGcYHSu0DNSy7Hkq,代码行数:12,代码来源:AppServiceProvider.php
示例4: process
/**
* Process video upload
*
* @param \Illuminate\Http\Request $request The form with the needed data
* @return \Illuminate\Http\RedirectResponse
*/
public function process(Request $request)
{
//validation rules
$rules = ['title' => 'required', 'category_list' => 'required', 'user_id' => 'required', 'video' => 'isneededvideo'];
//validation messages
$msgs = ['title.required' => 'A cím kitöltése kötelező!', 'category_list.required' => 'A kategória kiválasztása kötelező!', 'user_id.required' => 'A szerző kiválasztása kötelező!', 'video.required' => 'Videó nélkül nincs mit feltölteni!', 'isneededvideo' => 'A videónak mp4 vagy webm formátumúnak kell lennie!'];
\Validator::extend('isneededvideo', function ($attr, $value, $params) {
return $value->getMimeType() == 'video/mp4' || $value->getMimeType() == 'video/webm';
});
$validator = \Validator::make($request->all(), $rules, $msgs);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator->errors())->withInput($request->all());
}
//ease up coding with some shortcuts
$file = $request->file('video');
$extension = strtolower($file->getClientOriginalExtension());
$video = \App\Models\Video::create($request->except('video', 'category_list'));
//set video filename
$video->video = $video->getKey() . '.' . $extension;
//move video file
$file->move(public_path() . '/videos/', $video->video);
//save object
$video->save();
//sync pivot
$video->categories()->sync(array_filter($request->input('category_list')));
//do the capture
$this->capture($video);
return redirect('/');
}
示例5: boot
public function boot()
{
\Validator::extend('alpha_spaces', function ($attribute, $value, $parameters) {
return preg_match('/^([-a-z - _-ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîï
ðñòóôõöùúûüýøþÿÐdŒ-\\s])+$/i', $value);
});
}
示例6: rules
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
\Validator::extend('badword', function ($attribute, $value, $parameters) {
return !BadWord::where('word', 'LIKE', "%{$value}%")->exists();
});
return ['receiver' => 'badword', 'message' => 'badword'];
}
示例7: post
public function post()
{
// Only permit logged in users to comment
if (Auth::check()) {
// Add a rule to verify the particular item exists
Validator::extend('itemExists', function ($attribute, $value, $parameters) {
$type = ucfirst(Input::get('type'));
$item = $type::find($value);
return $item;
});
// Validate the data
$validator = Validator::make(Input::all(), array('id' => 'itemExists', 'type' => 'in:doctor,companion,enemy,episode', 'title' => 'required|min:5', 'email' => 'required|email', 'content' => 'required'), array('required' => 'You forgot to include the :attribute on your comment!', 'itemExists' => 'If you can see this, the universe is broken because that ' . Input::get('type') . ' does not exist.'));
if ($validator->fails()) {
return Redirect::to(URL::previous() . '#comments')->withErrors($validator)->withInput();
} else {
$comment = new Comment();
$comment->user_id = Auth::id();
$comment->item_id = Input::get('id');
$comment->item_type = Input::get('type');
$comment->title = Input::get('title');
$comment->content = Input::get('content');
$comment->save();
return Redirect::to(URL::previous() . '#comments')->with('message', 'Comment posted');
}
}
}
示例8: save
/**
* Handles both creating new client and updating an existing client.
*
* @return Response
*/
public function save()
{
## Form Validation ##
Validator::extend('phone', function ($attribute, $value, $parameters) {
if (preg_match('/^[0-9]+$/', $value)) {
return true;
} else {
return false;
}
});
## Define Rules ##
$rules = array('site_name' => 'required', 'contact_person' => 'required', 'contact_type' => 'required', 'phone_number' => 'required|phone', 'cell_number' => 'phone', 'address' => 'required', 'town' => 'required', 'province' => 'required', 'postal_code' => 'required', 'office_distance' => 'required|numeric|min:0', 'bill_rate' => 'required|numeric|min:0');
## Define Error Message ##
$message = array('site_name.required' => Lang::get('clients.site_require'), 'contact_person.required' => Lang::get('clients.contact_require'), 'contact_type.required' => Lang::get('clients.contact_type_require'), 'phone_number.required' => Lang::get('clients.phone_require'), 'address.required' => Lang::get('clients.address_require'), 'town.required' => Lang::get('clients.town_require'), 'province.required' => Lang::get('clients.province_require'), 'postal_code.required' => Lang::get('clients.postal_code_require'), 'office_distance.required' => Lang::get('clients.office_distance_require'), 'phone_number.phone' => Lang::get('clients.phone_invalid'), 'cell_number.phone' => Lang::get('clients.cell_number_invalid'));
$validator = Validator::make(Input::all(), $rules, $message);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
##------to create /update client-------##
$result = FleetClient::saveClient();
if ($result == true) {
return Redirect::to('fleets/clients')->with('success', Lang::get('clients.client_saved'));
} else {
return Redirect::back()->with('error', $result);
}
}
示例9: postSettings
public function postSettings()
{
// Hex RGB Custom Validator
Validator::extend('hex', function ($attribute, $value, $parameters) {
return preg_match("/^\\#[0-9A-Fa-f]{6}\$/", $value);
});
// Validation Rules
$rules = ['nc-color' => 'required|hex', 'tr-color' => 'required|hex', 'vs-color' => 'required|hex', 'time-format' => 'required|in:12,24'];
// Validation
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::back();
}
// Save Hex and Dark Hex colors to Session
foreach (['nc', 'tr', 'vs'] as $faction) {
$color = strtolower(Input::get("{$faction}-color"));
// Chosen color
Session::put("faction-colors.{$faction}.default", $color);
// Color darkened by 50%
Session::put("faction-colors.{$faction}.dark", $this->adjustColorLightenDarken($color, 50));
// Outline color
if ($color == Config::get("ps2maps.faction-colors.{$faction}.default")) {
// If color is default color, use white outline
$outline = "#FFF";
} else {
// Otherwise use calculated outline color
$outline = $this->closerToBlackOrWhite(Input::get("{$faction}-color")) == "#FFF" ? "#000" : "#FFF";
}
Session::put("faction-colors.{$faction}.outline", $outline);
}
// Save time format to session
Session::put('time-format', Input::get('time-format'));
return Redirect::back()->with('message', 'Settings Saved');
}
示例10: __construct
public function __construct()
{
Validator::extend('file', function ($attribute, $value, $parameters) {
$permitidos = ['application/msword' => 'doc', 'application/pdf' => 'pdf', 'application/rtf' => 'rtf', 'application/vnd.kde.kspread' => 'ksp', 'application/vnd.kde.kword' => 'kwd', 'application/vnd.ms-excel' => 'xls', 'application/vnd.ms-excel.addin.macroenabled.12' => 'xlam', 'application/vnd.ms-excel.sheet.binary.macroenabled.12' => 'xlsb', 'application/vnd.ms-excel.sheet.macroenabled.12' => 'xlsm', 'application/vnd.ms-excel.template.macroenabled.12' => 'xltm', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx', 'application/vnd.ms-word.document.macroenabled.12' => 'docm', 'application/vnd.ms-word.template.macroenabled.12' => 'dotm', 'application/vnd.ms-xpsdocument' => 'xps', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'dotx', 'application/xml' => 'xml', 'image/bmp' => 'bmp', 'image/x-ms-bmp' => 'bmp', 'image/jpeg' => 'jpeg', 'image/jpg' => 'jpg', 'image/png' => 'png'];
return in_array($value, $permitidos);
});
}
示例11: validator
public function validator(array $data)
{
\Validator::extend('passcheck', function () {
$value = \Request::input('old_password');
return \Hash::check($value, \Auth::user()->password);
});
return \Validator::make($data, ['password' => 'required|confirmed|min:6', 'old_password' => 'required|passcheck'], ['old_password.required' => 'Паролата е задължителна.', 'old_password.passcheck' => 'Грешна парола.', 'password.required' => 'Паролата е задължителна.', 'password.confirmed' => 'Потвърдената парола е грешна.', 'password.min' => 'Минимална дължина на паролата 6 символа.']);
}
示例12: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// Custom validation methods
\Validator::extend('is_image', function ($attribute, $value, $parameters, $validator) {
$imageMimes = ['image/png', 'image/bmp', 'image/gif', 'image/jpeg', 'image/jpg', 'image/tiff', 'image/webp'];
return in_array($value->getMimeType(), $imageMimes);
});
}
示例13: __construct
public function __construct()
{
Validator::extend('skinmimes', function ($attribute, $value, $parameters) {
$allowed = array('audio/mpeg', 'image/jpeg', 'application/ogg', 'audio/wave', 'audio/aiff', 'image/png', 'text/plain');
$mime = new MimeReader($value->getRealPath());
return in_array($mime->get_type(), $allowed);
});
}
示例14: __construct
public function __construct()
{
parent::__construct();
\Validator::extend('seats_capacity', function ($attribute, $value, $parameters) {
// dd($this->attributes);
return $this->attributes['seats_economy'] * 1 + $this->attributes['seats_business'] * 2 + $this->attributes['seats_firstclass'] * 4 <= $parameters[0];
//Kupowany samolot nie może mieć więcej foteli niż pojemność kadłuba
});
}
示例15: boot
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
\Validator::extend('sets', function ($attribute, $value, $parameters) {
$as = explode(',', $value);
return empty(array_diff($as, $parameters));
});
$this->loadTranslationsFrom(__DIR__ . '/../lang', 'tsotsi');
$this->publishes([__DIR__ . '/../../lang' => base_path('resources/lang/vendor/tsotsi')]);
}