Skip to content

Instantly share code, notes, and snippets.

@ashitvora-zz
Created November 21, 2012 11:48
Show Gist options
  • Save ashitvora-zz/4124501 to your computer and use it in GitHub Desktop.
Save ashitvora-zz/4124501 to your computer and use it in GitHub Desktop.
Laravel macro to display first validation error for the field
/**
* 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