Wrap Form Elements With This Form Macro

This trick is handy for wrapping all of your form elements with the same HTML/classes, which is especially useful for handling error states when using frameworks like Bootstrap or Foundation.

$errors = Session::get('errors', new Illuminate\Support\MessageBag);
Form::macro('bootwrapped', function($name, $label, $callback) use ($errors)
return sprintf(
'<div class="form-group %s">
<label class="control-label">%s</label>
$errors->has($name) ? 'has-error' : '',
$errors->first($name, '<span class="help-block">:message</span>')
Form::bootwrapped('email', 'Email', function($name)
return Form::text($name, null, ['class' => 'form-control']);
Made with ❤ by Chris Hayes