Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

houzek's avatar

Laravel 5 Form Builder

Hello,

I would like to show you a package that i created - Laravel 5 Form Builder. Here's the packagist link:

https://packagist.org/packages/kris/laravel-form-builder

I know that Laravels Form builder class will not be included by default in version 5, so this package uses that Form builder and creates a wrapper around it similar to Symfony's form builder.

It is still in dev phase ( mostly because laravel 5 is also ), and i want to check if I am on good path and if even people will want to use it.

For now it only supports Laravel 5.

If you have any critics, ideas or anything else, please let me know.

Also any PRs are welcome.

0 likes
25 replies
aspiresuvedi's avatar

I have been using this form for my project . Its great but sometimes when I need more configurations options I find it difficult to enhance .

mmcnairy's avatar

I love it for creating forms but I can't edit forms with it. I get error: "Undefined variable: form (View: /home/vagrant/workspace/inventory5/resources/views/projects/edit.blade.php)"

My edit controller looks like this:

public function edit($id,FormBuilder $formBuilder) { $project = Project::findOrFail($id);

    $form = $formBuilder->create('\App\Forms\ProjectForm', [
            'method' => 'PUT',
            'url'    => route('projects.update', $id),
            'model'  => $project
    ]);

    return view('projects.edit', compact('form'));
}

View looks like this:

@extends('layout.default') @section('content')

{!! form($form) !!}

@stop

bobbybouwmann's avatar

This package seems to be cool, but what most people don't know is that illuminate\html is not supported anymore by the framework! This packages uses that...

The Laravel Collective is now updating some packages for Laravel including the html part laravelcollective/html http://laravelcollective.com/

1 like
PatrickBauer's avatar

@blackbird What do you mean? illuminate\html is still compatible with L5, why shouldn't it? Its just not included by default anymore.

1 like
houzek's avatar

@bobbybouwmann Is there any advantage of LaravelCollective Html over Illuminate one except the support?

I will maybe switch my package to use LaravelCollective, but cannot see any value of it at this moment.

bobbybouwmann's avatar

The illuminate package is not supported anymore, so any updates, security updates and so on won't be added there. Also the illuminate package does not have any support for laravel 5.1. The best package for the job is the LaravelCollective one ;)

houzek's avatar

I updated the latest version (1.6.10) to use LaravelCollective package :) Thanks :)

frezno's avatar

Until now the Illuminate and Collective versions are identical, just at the Collective there have been three or four additional methods been added (imho no real improtant ones), but as bobbybouwman said, as the Illuminate version isn't supported anymore, it's just a matter of time where it's mandatory to use the Collective one.

mariusp's avatar

Hello!

So what can we use instead of HTML/Form Builder (that's fully compatible/supported by Laravel 5.1)?

Thanks!

mariusp's avatar

So, the official "support" is to go with raw HTML written by hand?

ImanGh's avatar

I Wonder why kris/Formbuilder package just doesn't go into the core of laravel ?! (0_o)

bobbybouwmann's avatar

@ImanGh It was in the core of Laravel (Laravel 4). It was removed so Taylor could focus on the back-end and not on the front-end. Also Laravel is widely used for API's which don't need the html and form builder stuff

1 like
ImanGh's avatar

@bobbybouwmann I think in laravel 4 Days a lighter package with a different name was use by L4 which eventually removed in L5.

  • The existence of Elixir is a good demonstration that taylor is not only concerned about the BACK-end. It seems they do have the front end in mind.
  • And for API maker guys. they better use the nimble Lumen.(not the hefty laravel). ;)
bobbybouwmann's avatar

@ImanGh Elixir is maintained and build by Jeffrey, Taylor has nothing to do with that.

The package was called HTML & Form and it's still the same, only maintained by laravelcollective now

ImanGh's avatar

@bobbybouwman Any way, the policy of the laravel framework, is not back-end only. I think providing some variation of form builder package is not a sham at all. (since symfony has form builder classes.) just like the integrated pack which was inspired from codeception and behat (by Jeffry Way) and now is in the core in order to streamline testing process.

ImanGh's avatar

@houzek Hi, why you do not expose your public API like this ? So users can take benefit of IDE auto-completion.

class Login extends FormHelpers
{
    public function buildForm()
    {
        
        $this->email('user_email');   // Method name represents the field name
        $this->password('user_password');
        $this->submit('submit');
        ;
    }
}

this class can handle that as a thin wrapper around your current add() method. (and doc blocks provide the auto-completion.)


    /**
     * @method $this text(      string  $field_name, array $options =[] , boolean $modify = false)
     * @method $this textarea(  string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this radio(     string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this checkbox(  string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this select(    string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this email(     string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this hidden(    string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this password(  string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this image(     string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this number(    string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this file(      string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this submit(    string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this url(       string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this tel(       string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this search(    string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this color(     string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this date(      string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this month(     string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this week(      string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this range(     string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this time(      string  $field_name, array $options = [] , boolean $modify = false)
     * @method $this select(    string  $field_name, array $options = [] , boolean $modify = false)
     */
    
    class FormHelpers extends Form
    {
        public function __call($fieldType,$args = [])
        {
            $permitted = ['text','textarea','radio','checkbox','select','email',
             'hidden','select','password','image','number',
             'file','submit','url','tel','search',
             'color','date','month','week','range','time'
            ];
            if(!in_array($fieldType,$permitted))
                return $this;

            $this->fieldName =  $args[0];
            $options = [];
            $modify = false;

            if( isset($args[1]) ) $options = $args[1];
            if( isset($args[2]) ) $modify = $args[2];

            $this->add($this->fieldName, $fieldType, $options, $modify);

            return $this;
        } 
}
YunusDev's avatar

Hello. What's the purpose of this form builder please.. is it serving a purpose like Google forms.. so therefore I can configure fields I want or it jst help creating a form easily from the backend.. Thanks.. Am looking to create something dynamic like Google form

Please or to participate in this conversation.