Skip to content

Instantly share code, notes, and snippets.

@KyleGawryluk
Last active December 29, 2015 11:29
Show Gist options
  • Save KyleGawryluk/7663759 to your computer and use it in GitHub Desktop.
Save KyleGawryluk/7663759 to your computer and use it in GitHub Desktop.
Add error messages to Jeffery Way's FormField class
/**
* Create the form field
*
* @param string $name
* @param array $args
*/
protected function createField($name, $args)
{
// If the user specifies an input type, we'll just use that.
// Otherwise, we'll take a best guess approach.
$type = array_get($args, 'type') ?: $this->guessInputType($name);
// We'll default to Bootstrap-friendly input class names
$args = array_merge(['class' => Config::get('form::inputClass')], $args);
$field = $this->createLabel($args, $name);
unset($args['label']);
$field .= $this->createInput($type, $args, $name);
if(Session::has('errors')){
$messages = Session::get('errors');
if($messages->first($name)){
$field .= '<span class="help-block">'.$messages->first($name).'</span>';
}
}
return $field;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment