kristijanhusak / laravel4-form-builder by kristijanhusak

Laravel form builder - symfony like
Package Data
Maintainer Username: kristijanhusak
Maintainer Contact: (Kristijan Husak)
Package Create Date: 2015-01-28
Package Last Update: 2015-06-30
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-04-11 03:12:08
Package Statistics
Total Downloads: 8,925
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 22
Total Watchers: 6
Total Forks: 8
Total Open Issues: 2

Build Status Coverage Status Total Downloads Latest Stable Version License

Laravel 4 form builder

Form builder for Laravel 4 inspired by Symfony's form builder. With help of Laravels FormBuilder class creates forms that can be easy modified and reused. By default it supports Bootstrap 3.

Laravel 5

For laravel 5 version check laravel-form-builder


For detailed documentation refer to

Note There are small differences between version 4 and 5 (Configuration path, etc.), so please be aware of those.


Changelog can be found here


    "require": {
        "kris/laravel4-form-builder": "1.6.*"

run composer update

Then add Service provider to config/app.php

    'providers' => [
        // ...

And Facade (also in config/app.php)

    'aliases' => [
        // ...
        'FormBuilder' => 'Kris\LaravelFormBuilder\Facades\FormBuilder'

Quick start

Creating form classes is easy. Lets assume PSR-4 is set for loading namespace App in app/Project folder. With a simple artisan command we can create form:

php artisan make:form app/Project/Forms/SongForm --fields="name:text, lyrics:textarea, publish:checkbox"

Form is created in path app/Project/Forms/SongForm.php with content:

<?php namespace App\Forms;

use Kris\LaravelFormBuilder\Form;

class SongForm extends Form
    public function buildForm()
            ->add('name', 'text')
            ->add('lyrics', 'textarea')
            ->add('publish', 'checkbox');

If you want to instantiate empty form without any fields, just skip passing --fields parameter:

    php artisan make:form app/Project/Forms/PostForm


<?php namespace App\Forms;

use Kris\LaravelFormBuilder\Form;

class PostForm extends Form
    public function buildForm()
        // Add fields here...

After that instantiate the class in the controller and pass it to view:

<?php namespace App/Http/Controllers;

use Illuminate\Routing\Controller as BaseController;
use Kris\LaravelFormBuilder\FormBuilder;

class SongsController extends BaseController {

    public function create()
        $form = \FormBuilder::create('App\Forms\SongForm', [
            'method' => 'POST',
            'url' => route('')

        return view('song.create', compact('form'));

Print the form in view with form() helper function:

<!-- resources/views/song/create.blade.php -->


    {{{ form($form) }}}

Above code will generate this html:

<form method="POST" action="">
    <input name="_token" type="hidden" value="FaHZmwcnaOeaJzVdyp4Ml8B6l1N1DLUDsZmsjRFL">
    <div class="form-group">
        <label for="name" class="control-label">Name</label>
        <input type="text" class="form-control" id="name">
    <div class="form-group">
        <label for="lyrics" class="control-label">Lyrics</label>
        <textarea name="lyrics" class="form-control"></textarea>
    <div class="form-group">
        <label for="publish" class="control-label">Publish</label>
        <input type="checkbox" name="publish" id="publish">


Project follows PSR-2 standard and it's covered with PHPUnit tests. Pull requests should include tests and pass Travis CI build.

To run tests first install dependencies with composer install.

After that tests can be run with vendor/bin/phpunit