Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Laravel 4 Basics Blade & Forms Form Builder

Jarrod Tanton
PLUS
Jarrod Tanton
Courses Plus Student 10,802 Points

Help for Others - Using Blade Syntax with a Framework (like bootstrap)

For those of you who watching this, that might want to have the ability to use the blade syntax for the form builder in combination with a framework like Bootstrap. Here are the steps.

  1. Create a new provider (you can use php artisan for this) In my case, I created one title BootstrapFormServiceProvider.

  2. In the boot method of the provider specify the new type of element you want to create and what it expects. (i.e. I wanted to use Bootstrap so I created a newStatic method for bsText using the syntax below.

Form::component('bsText', 'components.form.text', ['name', 'value' => null, 'attributes' => []]);

  1. Register the service provider by editing the app.php file in the confit folder. This is done by adding something like the below to the bottom of 'providers':

App\Providers\BootstrapFormServiceProvider::class

  1. run composer update

  2. Create the file that specifies how the bsText method you created in step 2 will work. In my case, the file will be stored at 'components.form.text' (what we specified in step 2) and will contain the following.

<fieldset class="form-group"> {{ Form::label($name, null, ['class' => 'control-label']) }} {{ Form::text($name, $value, array_merge(['class' => 'form-control'], $attributes)) }} </fieldset>

  1. Use the method in your view. In my case, I added this inside of my form:

{{ Form::bsText('title') }}

  1. Enjoy the benefits! Now just from typing that one line of code you will get the bootsrtap html needed for an input. Here's the html that will be generated!

<fieldset class="form-group"> <label for="title" class="control-label">Title</label> <input class="form-control" name="title" type="text" id="title"> </fieldset>

Hope this helps!

You can find more information on the laravel collective site:

https://laravelcollective.com/docs/5.2/html#custom-components