Created
November 21, 2012 11:48
-
-
Save ashitvora-zz/4124501 to your computer and use it in GitHub Desktop.
Laravel macro to display first validation error for the field
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
/** | |
* Returns first error message for a field, if any, in html | |
*/ | |
Form::macro('first_field_error', function($field_name){ | |
$html = array(); | |
$errors = Session::get('errors'); | |
if( $errors->has( $field_name ) ){ | |
array_push( $html, '<div class="form-error">' ); | |
array_push( $html, $errors->first( $field_name ) ); | |
array_push( $html, '</div>' ); | |
} | |
return implode("", $html); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment