Skip to content

Instantly share code, notes, and snippets.

@tiagodavi
Created September 17, 2014 20:22
Show Gist options
  • Save tiagodavi/72a506e0d10db1194a6f to your computer and use it in GitHub Desktop.
Save tiagodavi/72a506e0d10db1194a6f to your computer and use it in GitHub Desktop.
<?php
// app/classes/myrules.php
class MyRules
{
// note this is a static method
public static function _validation_unique($val, $options)
{
list($table, $field, $id) = explode('.', $options);
$result = DB::select("LOWER (\"$field\")", 'id')
->where($field, '=', Str::lower($val))
->from($table)
->execute();
if($result->count() > 0){
$data = $result->as_array();
return (empty($id)) ? false : ($data[0]['id'] == $id);
}else{
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment