Skip to content

Instantly share code, notes, and snippets.

@stevenwoodson
Created March 20, 2014 22:26
Show Gist options
  • Save stevenwoodson/9675310 to your computer and use it in GitHub Desktop.
Save stevenwoodson/9675310 to your computer and use it in GitHub Desktop.
Laravel 4 Custom Validation - check for field already used today
// Return an error if $value was found in a record from today
Validator::extend('unique_today', function($attribute, $value, $parameters) {
if ( $this->findAll( null, array( $attribute => $value, 'from' => date('Y-m-d') ) )->count() ) {
return false;
}
return true;
});
Validator::replacer('unique_today', function($message, $attribute, $rule, $parameters) {
return Lang::get('error_enteredtoday', array('attribute' => $attribute));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment