Working on a Laravel App refactoring (will post more on this soon), I discovered a challenge: Integrating Twitter Bootstrap Form layouts into Laravel Blade templates.
Twitter Bootstrap has a whole lot of design options for forms:
- Validation states (success/error)
- Validation marks
- Error messages
However, using them, requires wrapping each form element in his own div, adding classes based on status etc. Doing this for every single one of them is rather tiring, so I wrote (up to now) two blades, that display password and text fields and wraps them accordingly.
You can find them here on Github.
The Laravel blade assumes that three variables are given:
- $field: The name of the field
- $context: The context, which is basically the name of the appropriate language file
- $error: The Laravel error messages bag
Further, the language variable should be like this
- ‘field’ - Name of the field
- field_placeholder - Placeholder of the input field
For example,for the field email I would include this blade by using
While having the following within lang/en/user.php
This drastically reduces the amount of code, I have to write to insert a new field and allows to make central changes to all forms, if required.
Feel free to comment, copy or branch :D