Skip to content

Instantly share code, notes, and snippets.

@vojtasvoboda
Created January 4, 2016 10:33
Show Gist options
  • Save vojtasvoboda/9a163b3fcc9b4780d701 to your computer and use it in GitHub Desktop.
Save vojtasvoboda/9a163b3fcc9b4780d701 to your computer and use it in GitHub Desktop.
Register custom model validator in OctoberCMS
<?php
namespace Acme\Plugin\Models;
use Acme\Plugin\Validators\ExtendedValidator;
use Model as BaseModel;
use Illuminate\Support\Facades\Validator;
// registrate own validator
Validator::resolver(function($translator, $data, $rules, $messages) {
return new ExtendedValidator($translator, $data, $rules, $messages);
});
class Model extends BaseModel {
public $rules = [
'name' => 'required|max:10',
'birth_number' => 'required|regex:/[0-9]{9,10}/|birthNumber'
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment