, ,

Laravel html helpers with Laravel Collective Packages

We need to install http://laravelcollective.com.

HTML: HTML helpers for creating common HTML and form elements

Run

composer require "laravelcollective/html":"^5.2.0"

 

OR edit composer.json, Add

"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"laravelcollective/html": "5.1.*"
},

Run

composer update

Edit config/app.php.

Add to the provider array

App\Providers\RouteServiceProvider::class,
Collective\Html\HtmlServiceProvider::class,

Add to the aliases array

'View' => Illuminate\Support\Facades\View::class,
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,

Usage

Normally our code like this.

<form action="contact">
<label>First name:</label>
<input type="text" name="firstname" value="Enter your first name">
<br />
<label>Last name:</label>
<input type="text" name="lastname" value="Enter your last name">
<br />
<input type="submit" value="Submit">
</form>

Using the HTML Package

{!! Form::open(array ('url' => 'contact')) !!}
{!! Form::label('First name') !!}
{!! Form::text('firstname', 'Enter your first name') !!}
<br />
{!! Form::label('Last name') !!}
{!! Form::text('lastname', 'Enter your last name') !!}
<br />
{!! Form::submit() !!}
{!! Form::close() !!}