In this chapter, you will learn how to use Laravel's form builder. The form builder will be demonstrated to facilitate the building of the following elements:
Finally, we'll see an example of how to use the form builder to create the month, date, and year selection elements for the accommodations reservation software form, and how to create a macro to reduce the code duplication.
The form builder package in Laravel 4 is called HTML. This was used to help you create HTML, particularly developers who also have to perform web designer duties but prefer to use Laravel facades and helper methods. For example, the following Laravel facade select()
method, where the options for the language, British and American English in this example, are passed as an array parameter:
Form::select('language', ['en-us' => 'English (US)','en-gb' => 'English (UK)']);
This can be used as an alternative to the standard HTML, which requires much more repetitious code, as shown in the following code:
<select name="language"> <option value="en-us">English (US)</option> <option value="en-gb">English (UK)</option> </select>
Since frameworks are constantly evolving, they need to adapt to fulfill the needs of most of their users. Also, whenever possible, they should continue to be more efficient. In some cases, this means rewriting or refactoring pieces of the framework, adding features, or even removing them.
As strange as it may seem, there are several valid reasons for removing the features. The following is a list of reasons for removing packages:
In this particular case, certain Laravel packages were removed to lighten up the overall experience and to move toward a more component-based approach, which is similar to that used in Symfony.