PHPackages                             symphonygf/laravel-form - 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. symphonygf/laravel-form

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

symphonygf/laravel-form
=======================

This packages integrates Symfony Form Component in Laravel.

v1.0.2.x-dev(3y ago)024MITPHPPHP ^7.2|^8

Since Aug 30Pushed 3y ago1 watchersCompare

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

READMEChangelogDependencies (7)Versions (3)Used By (0)

Laravel Form
------------

[](#laravel-form)

See

Laravel integration:

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

### Install

[](#install)

- `composer require fadeevGosha/laravel_form`
- Add `Yobidoyobi\Form\ServiceProvider::class,` to you ServiceProviders.
- (optional) Add `'FormFactory' => Yobidoyobi\Form\Facade\FormFactory::class,` to your Facades.
- (optional) Add `'FormRenderer' => Yobidoyobi\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 Yobidoyobi\Form\ValidatesForms;
use Yobidoyobi\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

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

1349d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/53f3134452fa12fa2a647511577a5ac13299eeff06db53064512cfbcd26669db?d=identicon)[symphonygf](/maintainers/symphonygf)

---

Top Contributors

[![symphonygf](https://avatars.githubusercontent.com/u/72216217?v=4)](https://github.com/symphonygf "symphonygf (4 commits)")

---

Tags

laravel-formsymphonygf-laravelsymphonygfsymphonygf-forms

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k16.7M309](/packages/easycorp-easyadmin-bundle)[barryvdh/laravel-form-bridge

This packages integrates Symfony Form Component in Laravel.

163354.8k1](/packages/barryvdh-laravel-form-bridge)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[friendsofsymfony/comment-bundle

This Bundle provides threaded comment functionality for Symfony applications

460751.2k5](/packages/friendsofsymfony-comment-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[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)

PHPackages © 2026

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