PHPackages                             barryvdh/laravel-form-bridge - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. barryvdh/laravel-form-bridge

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

barryvdh/laravel-form-bridge
============================

This packages integrates Symfony Form Component in Laravel.

v0.7.5(2mo ago)163354.8k↓15.8%29[8 issues](https://github.com/barryvdh/laravel-form-bridge/issues)[1 PRs](https://github.com/barryvdh/laravel-form-bridge/pulls)1MITPHPPHP ^8CI passing

Since Apr 28Pushed 2mo ago9 watchersCompare

[ Source](https://github.com/barryvdh/laravel-form-bridge)[ Packagist](https://packagist.org/packages/barryvdh/laravel-form-bridge)[ RSS](/packages/barryvdh-laravel-form-bridge/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (14)Versions (41)Used By (1)

Laravel Form Bridge
-------------------

[](#laravel-form-bridge)

See

Laravel integration:

- Pre-set old input
- Add validation errors
- Translate field names

### Install

[](#install)

- `composer require barryvdh/laravel-form-bridge`
- Add `Barryvdh\Form\ServiceProvider::class,` to you ServiceProviders.
- (optional) Add `'FormFactory' => Barryvdh\Form\Facade\FormFactory::class,` to your Facades.
- (optional) Add `'FormRenderer' => Barryvdh\Form\Facade\FormRenderer::class,` to your Facades.

### Basic example

[](#basic-example)

You can use the FormFactory to create a form. You can supply a Model as data, so it will fill the values.

You can use `$form->handleRequest($request);` to update the values in the user, or you can just use `$request` object or `Input` facade like usual. However, by default, the form is grouped under a `form` key, so you have to use `$request->get('form')` to get the form values. Or you can create a Named form, with an empty name.

If you need to set more options, use the `createBuilder` function instead of `create`, to be able to use `setAction()` etc. You need to call `->getForm()` to get the actual form instance again.

```
use FormFactory;
use Illuminate\Http\Request;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;

Route::any('create', function()
{
    $user = App\User::first();

    $form = FormFactory::create(FormType::class, $user)
        ->add('name', TextType::class)
        ->add('email', EmailType::class, [
            'rules' => 'unique:users,email',
        ])
        ->add('save', SubmitType::class, ['label' => 'Save user']);

    $form->handleRequest();

    if ($form->isSubmitted() && $form->isValid()) {
        // Save the user with the new mapped data
        $user->save();

        return redirect('home')->withStatus('User saved!');
    }

    return view('user.create', compact('form'));
});
```

Use the following in your Blade templates:

```
@formStart($form)
@formWidget($form)
@formEnd($form)
```

Other directives are: @form, @formLabel, @formErrors, @formRest and @formRow

```
@form($form)
```

```
@formStart($form)

Name
@formLabel($form['name'], 'Your name')
@formWidget($form['name'], ['attr' => ['class' => 'name-input']])

Rest
@formRest($form)

@formEnd($form)
```

Or use the following in your Twig templates to render the view:

```
{{ formStart(form) }}
{{ formWidget(form) }}
{{ formEnd(form) }}
```

See  for more options.

Traits
------

[](#traits)

To make it easier to use in a Controller, you can use 2 traits:

ValidatesForms: Adds a validation method, similar to the ValidatesRequests trait: `$this->validateForm($form, $request, $rules)`

CreatesForms: Create a Form or FormBuilder:

- createForm($type, $data, $options) -&gt; Form for a type (`form` or a Type class)
- createNamed($name, $type, $data, $options) -&gt; Form with a given name
- createFormBuilder($data, $options) -&gt; FormBuilder with an empty name
- createNamedFormBuilder($name, $data, $options) -&gt; FormBuilder with a given name

```
use Barryvdh\Form\ValidatesForms;
use Barryvdh\Form\CreatesForms;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;

class UserController extends Controller{

    use ValidatesForms, CreatesForms;

    public function anyIndex(Request $request)
    {
        $user = User::first();

        $form = $this->createFormBuilder($user)
            ->add('name', TextType::class)
            ->add('email', EmailType::class)
            ->add('save', SubmitType::class, ['label' => 'Save user'])
            ->getForm();

        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $this->validateForm($form, $request, [
                'name' => 'required',
                'email' => 'required|email',
            ]);

            $user->save();
        }

        return view('user', ['form' => $form->createView()]);
    }
}
```

Creating a named form:

```
use Symfony\Component\Form\Extension\Core\Type\FormType;

$form = $this->createNamed('user', FormType::class, $user)
    ->add('name', TextType::class)
    ->add('email', EmailType::class)
    ->add('save', SubmitType::class, ['label' => 'Save user']);
```

See  for more information.

BelongsToMany relations
-----------------------

[](#belongstomany-relations)

BelongsToMany behaves differently, because it isn't an actual attribute on your model. Instead, we can set the `mapped` option to `false` and sync it manually.

```
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

$builder->add('users', ChoiceType::class, [
    'choices' => \App\User::pluck('name', 'id'),
    'multiple' => true,
    'mapped' => false,
    'expanded' => true, // true=checkboxes, false=multi select
]);
```

```
$form->handleRequest($request);
if ($form->isSubmitted()) {
    $this->validate($request, $rules);

    $item->save();
    $item->users()->sync($form->get('users')->getData());

    return redirect()->back();
}
```

See for more options the [choice type documentation](http://symfony.com/doc/current/reference/forms/types/choice.html).

> Note: The BelongsToManyType is deprecated in favor of the ChoiceType from Symfony.

Translation labels
------------------

[](#translation-labels)

If you want to translate your labels automatically, just pass the translation key as the `label` attribute. It will run throught Twig's `trans` filter.

```
->add('name', TextType::class, ['label' => 'fields.name'])
```

Uploading Files
---------------

[](#uploading-files)

You can use the `file` type in the FormBuilder, and use the magic `getFile()` and `setFile()` method on your Model or mark it as not mapped, so you can handle it yourself. See [http://symfony.com/doc/current/cookbook/doctrine/file\_uploads.html](http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html)

```
Class User extends Model {

    /** @var UploadedFile  */
    private $file;

    public function getFile()
    {
        return $this->file;
    }

    public function setFile(UploadedFile $file = null)
    {
        $this->file = $file;
    }

    public function upload()
    {
        // the file property can be empty if the field is not required
        if (null === $this->getFile()) {
            return;
        }

        // use the original file name here but you should
        // sanitize it at least to avoid any security issues

        // move takes the target directory and then the
        // target filename to move to
        $this->getFile()->move(
            $this->getUploadRootDir(),
            $this->getFile()->getClientOriginalName()
        );

        // set the path property to the filename where you've saved the file
        $this->path = $this->getFile()->getClientOriginalName();

        // clean up the file property as you won't need it anymore
        $this->file = null;
    }
}
```

```
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;

$user = User::first();

$form = $this->createFormBuilder($user)
    ->add('name', TextType::class)
    ->add('file', FileType::class)
    ->add('save', SubmitType::class, ['label' => 'Save user'])
    ->getForm();

$form->handleRequest($request);

if ($form->isValid()) {
    $user->upload();
    $user->save();
}
```

Extending
---------

[](#extending)

You can extend some of the arrays in the ServiceProvider, eg. to add Types, add this to the `register()` method in your own ServiceProvider:

```
$this->app->extend('form.types', function($types, $app){
    $types[] = new CustomType();
    return $types;
});
```

###  Health Score

60

—

FairBetter than 99% of packages

Maintenance83

Actively maintained with recent releases

Popularity53

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 84.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~113 days

Recently: every ~279 days

Total

36

Last Release

81d ago

PHP version history (5 changes)v0.1.0PHP &gt;=5.4.0

v0.2.0PHP &gt;=5.5.0

v0.4.2PHP &gt;=7

v0.6.0PHP ^7.2|^8

v0.7.0PHP ^8

### Community

Maintainers

![](https://www.gravatar.com/avatar/dad47b02be23edb7094a151b4b1ce7e9cb56b75cd87cd3341d140e1e1e9cd0e4?d=identicon)[barryvdh](/maintainers/barryvdh)

---

Top Contributors

[![barryvdh](https://avatars.githubusercontent.com/u/973269?v=4)](https://github.com/barryvdh "barryvdh (172 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (6 commits)")[![martintern](https://avatars.githubusercontent.com/u/13314337?v=4)](https://github.com/martintern "martintern (4 commits)")[![sergiy-petrov](https://avatars.githubusercontent.com/u/8986207?v=4)](https://github.com/sergiy-petrov "sergiy-petrov (4 commits)")[![mmp2p](https://avatars.githubusercontent.com/u/35037225?v=4)](https://github.com/mmp2p "mmp2p (2 commits)")[![rojtjo](https://avatars.githubusercontent.com/u/1123887?v=4)](https://github.com/rojtjo "rojtjo (2 commits)")[![luukschakenraad](https://avatars.githubusercontent.com/u/8376948?v=4)](https://github.com/luukschakenraad "luukschakenraad (2 commits)")[![robinvalk](https://avatars.githubusercontent.com/u/3050565?v=4)](https://github.com/robinvalk "robinvalk (2 commits)")[![sailingdeveloper](https://avatars.githubusercontent.com/u/3988671?v=4)](https://github.com/sailingdeveloper "sailingdeveloper (1 commits)")[![SwenVanZanten](https://avatars.githubusercontent.com/u/3099122?v=4)](https://github.com/SwenVanZanten "SwenVanZanten (1 commits)")[![vv12131415](https://avatars.githubusercontent.com/u/17382248?v=4)](https://github.com/vv12131415 "vv12131415 (1 commits)")[![bonroyage](https://avatars.githubusercontent.com/u/4411748?v=4)](https://github.com/bonroyage "bonroyage (1 commits)")[![causamortis](https://avatars.githubusercontent.com/u/46485955?v=4)](https://github.com/causamortis "causamortis (1 commits)")[![kasparsklavins](https://avatars.githubusercontent.com/u/4699174?v=4)](https://github.com/kasparsklavins "kasparsklavins (1 commits)")[![motammem](https://avatars.githubusercontent.com/u/5410340?v=4)](https://github.com/motammem "motammem (1 commits)")[![patrickbussmann](https://avatars.githubusercontent.com/u/15617021?v=4)](https://github.com/patrickbussmann "patrickbussmann (1 commits)")[![pinodex](https://avatars.githubusercontent.com/u/6258767?v=4)](https://github.com/pinodex "pinodex (1 commits)")[![robotomarvin](https://avatars.githubusercontent.com/u/3751587?v=4)](https://github.com/robotomarvin "robotomarvin (1 commits)")

---

Tags

hacktoberfestlaravelformFormsformbuilder

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/barryvdh-laravel-form-bridge/health.svg)

```
[![Health](https://phpackages.com/badges/barryvdh-laravel-form-bridge/health.svg)](https://phpackages.com/packages/barryvdh-laravel-form-bridge)
```

###  Alternatives

[anahkiasen/former

A powerful form builder

1.4k1.4M14](/packages/anahkiasen-former)[lara-zeus/bolt

Zeus Bolt is form builder for your users, with so many use cases

23640.2k2](/packages/lara-zeus-bolt)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)[sulu/form-bundle

Bundle for creating forms in Sulu.

87287.3k7](/packages/sulu-form-bundle)[leapt/core-bundle

Symfony LeaptCoreBundle

2529.1k4](/packages/leapt-core-bundle)[lara-zeus/matrix-choice

Zeus Matrix Choice multiple choice grid component form for filamentPHP

2225.6k](/packages/lara-zeus-matrix-choice)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
