Download the PHP package barryvdh/laravel-form-bridge without Composer
On this page you can find all versions of the php package barryvdh/laravel-form-bridge. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download barryvdh/laravel-form-bridge
More information about barryvdh/laravel-form-bridge
Files in barryvdh/laravel-form-bridge
Package laravel-form-bridge
Short Description This packages integrates Symfony Form Component in Laravel.
License MIT
Informations about the package laravel-form-bridge
Laravel Form Bridge
See http://symfony.com/doc/current/forms.html
Laravel integration:
- Pre-set old input
- Add validation errors
- Translate field names
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
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 the following in your Blade templates:
Other directives are: @form, @formLabel, @formErrors, @formRest and @formRow
Or use the following in your Twig templates to render the view:
See http://symfony.com/doc/current/book/forms.html#form-rendering-template for more options.
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) -> Form for a type (
form
or a Type class) - createNamed($name, $type, $data, $options) -> Form with a given name
- createFormBuilder($data, $options) -> FormBuilder with an empty name
- createNamedFormBuilder($name, $data, $options) -> FormBuilder with a given name
Creating a named form:
See http://symfony.com/doc/current/book/forms.html for more information.
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.
See for more options the choice type documentation.
Note: The BelongsToManyType is deprecated in favor of the ChoiceType from Symfony.
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.
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
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:
All versions of laravel-form-bridge with dependencies
illuminate/support Version ^9|^10|^11.0
symfony/form Version ^6|^7.0
symfony/validator Version ^6|^7.0
symfony/twig-bridge Version ^6|^7.0
twig/twig Version ^3.3.8