Created
March 20, 2014 22:26
-
-
Save stevenwoodson/9675310 to your computer and use it in GitHub Desktop.
Laravel 4 Custom Validation - check for field already used today
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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