.
I'm trying to implement a personal validation, creating a new rule like documentation - the rule is "unique", that check if a username already exists in database.
I follow the documentation:
1) I create a file at "app/classes/myvalidation.php" with this code:
class Myvalidation {
public function _validation_unique($val, $options)
{
list($table, $field) = explode('.', $options);
$result = DB::select("LOWER (\"$field\")")
->where($field, '=', Str::lower($val))
->from($table)->execute();
return ! ($result->count() > 0);
}
}
$val = Validation::factory();
$val->add_callable('myvalidation');
// orginal
$val->add_field('name', 'Name', 'required|nomatch[Name *]');
// array method
$val->add_field('name', 'Name', array(
'required',
'nomatch[Name *]',
array($modelinstance, 'methodname'),
));
about it.
I did this:
1) Create a file named app/classes/myvalidation.php
2) Put this simple code:
public function _validation_nomatch($val, $input)
{
return ($val !== $input) ? true : false;
}
It looks like you're new here. If you want to get involved, click one of these buttons!