{"id":16068144,"url":"https://github.com/barryvdh/laravel-form-bridge","last_synced_at":"2026-02-27T13:29:39.906Z","repository":{"id":30710817,"uuid":"34266927","full_name":"barryvdh/laravel-form-bridge","owner":"barryvdh","description":"Laravel Bridge for the Symfony Form Component","archived":false,"fork":false,"pushed_at":"2026-02-23T11:44:06.000Z","size":190,"stargazers_count":162,"open_issues_count":10,"forks_count":29,"subscribers_count":9,"default_branch":"master","last_synced_at":"2026-02-23T19:56:51.548Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/barryvdh.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-04-20T14:55:40.000Z","updated_at":"2026-02-23T11:44:11.000Z","dependencies_parsed_at":"2024-03-02T11:26:19.043Z","dependency_job_id":"d9c05ab2-0527-4639-b33a-0037bd0363ab","html_url":"https://github.com/barryvdh/laravel-form-bridge","commit_stats":{"total_commits":164,"total_committers":19,"mean_commits":8.631578947368421,"dds":"0.24390243902439024","last_synced_commit":"5fdcc4d825025307e46282b9ae22afd083aeb2c8"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"purl":"pkg:github/barryvdh/laravel-form-bridge","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barryvdh%2Flaravel-form-bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barryvdh%2Flaravel-form-bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barryvdh%2Flaravel-form-bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barryvdh%2Flaravel-form-bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/barryvdh","download_url":"https://codeload.github.com/barryvdh/laravel-form-bridge/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barryvdh%2Flaravel-form-bridge/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29896757,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T12:09:13.686Z","status":"ssl_error","status_checked_at":"2026-02-27T12:09:13.282Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest"],"created_at":"2024-10-09T06:08:43.356Z","updated_at":"2026-02-27T13:29:39.875Z","avatar_url":"https://github.com/barryvdh.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Laravel Form Bridge\n\nSee http://symfony.com/doc/current/forms.html\n\nLaravel integration:\n - Pre-set old input\n - Add validation errors\n - Translate field names\n\n### Install\n - `composer require barryvdh/laravel-form-bridge`\n - Add `Barryvdh\\Form\\ServiceProvider::class,` to you ServiceProviders.\n - (optional) Add `'FormFactory' =\u003e Barryvdh\\Form\\Facade\\FormFactory::class,` to your Facades.\n - (optional) Add `'FormRenderer' =\u003e Barryvdh\\Form\\Facade\\FormRenderer::class,` to your Facades.\n\n### Basic example\n\nYou can use the FormFactory to create a form. You can supply a Model as data, so it will fill the values.\n\nYou can use `$form-\u003ehandleRequest($request);` to update the values in the user, or you can just use `$request` object or `Input` facade like usual.\nHowever, by default, the form is grouped under a `form` key, so you have to use `$request-\u003eget('form')` to get the form values.\nOr you can create a Named form, with an empty name.\n\nIf you need to set more options, use the `createBuilder` function instead of `create`, to be able to use `setAction()` etc. You need to call `-\u003egetForm()`  to get the actual form instance again.\n\n```php\nuse FormFactory;\nuse Illuminate\\Http\\Request;\nuse Symfony\\Component\\Form\\FormFactoryInterface;\nuse Symfony\\Component\\Form\\Extension\\Core\\Type\\FormType;\nuse Symfony\\Component\\Form\\Extension\\Core\\Type\\TextType;\nuse Symfony\\Component\\Form\\Extension\\Core\\Type\\EmailType;\nuse Symfony\\Component\\Form\\Extension\\Core\\Type\\SubmitType;\n\nRoute::any('create', function()\n{\n    $user = App\\User::first();\n    \n    $form = FormFactory::create(FormType::class, $user)\n        -\u003eadd('name', TextType::class)\n        -\u003eadd('email', EmailType::class, [\n            'rules' =\u003e 'unique:users,email',\n        ])\n        -\u003eadd('save', SubmitType::class, ['label' =\u003e 'Save user']);\n\n    $form-\u003ehandleRequest();\n\n    if ($form-\u003eisSubmitted() \u0026\u0026 $form-\u003eisValid()) {\n        // Save the user with the new mapped data\n        $user-\u003esave();\n        \n        return redirect('home')-\u003ewithStatus('User saved!');\n    }\n\n    return view('user.create', compact('form'));\n});\n```\n\nUse the following in your Blade templates:\n\n```php\n@formStart($form)\n@formWidget($form)\n@formEnd($form)\n```\n\nOther directives are: @form, @formLabel, @formErrors, @formRest and @formRow\n\n```php\n@form($form)\n```\n\n```php\n@formStart($form)\n\n\u003ch2\u003eName\u003c/h2\u003e\n@formLabel($form['name'], 'Your name')\n@formWidget($form['name'], ['attr' =\u003e ['class' =\u003e 'name-input']])\n\n\u003ch2\u003eRest\u003c/h2\u003e\n@formRest($form)\n\n@formEnd($form)\n```\n\nOr use the following in your Twig templates to render the view:\n\n```twig\n{{ formStart(form) }}\n{{ formWidget(form) }}\n{{ formEnd(form) }}\n```\n\nSee http://symfony.com/doc/current/book/forms.html#form-rendering-template for more options.\n\n## Traits\n\nTo make it easier to use in a Controller, you can use 2 traits:\n\nValidatesForms: Adds a validation method, similar to the ValidatesRequests trait:\n`$this-\u003evalidateForm($form, $request, $rules)`\n\nCreatesForms: Create a Form or FormBuilder:\n - createForm($type, $data, $options) -\u003e Form for a type (`form` or a Type class)\n - createNamed($name, $type, $data, $options) -\u003e Form with a given name\n - createFormBuilder($data, $options) -\u003e FormBuilder with an empty name\n - createNamedFormBuilder($name, $data, $options) -\u003e FormBuilder with a given name\n\n \n```php\nuse Barryvdh\\Form\\ValidatesForms;\nuse Barryvdh\\Form\\CreatesForms;\nuse Symfony\\Component\\Form\\Extension\\Core\\Type\\TextType;\nuse Symfony\\Component\\Form\\Extension\\Core\\Type\\EmailType;\nuse Symfony\\Component\\Form\\Extension\\Core\\Type\\SubmitType;\n\nclass UserController extends Controller{\n\n    use ValidatesForms, CreatesForms;\n    \n    public function anyIndex(Request $request)\n    {\n        $user = User::first();\n\n        $form = $this-\u003ecreateFormBuilder($user)\n            -\u003eadd('name', TextType::class)\n            -\u003eadd('email', EmailType::class)\n            -\u003eadd('save', SubmitType::class, ['label' =\u003e 'Save user'])\n            -\u003egetForm();\n\n        $form-\u003ehandleRequest($request);\n\n        if ($form-\u003eisSubmitted()) {\n            $this-\u003evalidateForm($form, $request, [\n                'name' =\u003e 'required',\n                'email' =\u003e 'required|email',\n            ]);\n\n            $user-\u003esave();\n        }\n\n        return view('user', ['form' =\u003e $form-\u003ecreateView()]);\n    }\n}\n```\n\nCreating a named form:\n\n```php\nuse Symfony\\Component\\Form\\Extension\\Core\\Type\\FormType;\n\n$form = $this-\u003ecreateNamed('user', FormType::class, $user) \n    -\u003eadd('name', TextType::class)\n    -\u003eadd('email', EmailType::class)\n    -\u003eadd('save', SubmitType::class, ['label' =\u003e 'Save user']);\n```\n\nSee http://symfony.com/doc/current/book/forms.html for more information.\n## BelongsToMany relations\n\nBelongsToMany 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.\n\n```php\nuse Symfony\\Component\\Form\\Extension\\Core\\Type\\ChoiceType;\n\n$builder-\u003eadd('users', ChoiceType::class, [\n    'choices' =\u003e \\App\\User::pluck('name', 'id'),\n    'multiple' =\u003e true,\n    'mapped' =\u003e false,\n    'expanded' =\u003e true, // true=checkboxes, false=multi select\n]);\n```\n\n```php\n$form-\u003ehandleRequest($request);\nif ($form-\u003eisSubmitted()) {\n    $this-\u003evalidate($request, $rules);\n\n    $item-\u003esave();\n    $item-\u003eusers()-\u003esync($form-\u003eget('users')-\u003egetData());\n\n    return redirect()-\u003eback();\n}\n```\nSee for more options the [choice type documentation](http://symfony.com/doc/current/reference/forms/types/choice.html).\n\n\u003e Note: The BelongsToManyType is deprecated in favor of the ChoiceType from Symfony.\n\n## Translation labels\n\nIf you want to translate your labels automatically, just pass the translation key as the `label` attribute. It will run throught Twig's `trans` filter.\n\n```php\n-\u003eadd('name', TextType::class, ['label' =\u003e 'fields.name'])\n```\n\n## Uploading Files\n\nYou 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\n\n```php\nClass User extends Model {\n\n    /** @var UploadedFile  */\n    private $file;\n\n    public function getFile()\n    {\n        return $this-\u003efile;\n    }\n\n    public function setFile(UploadedFile $file = null)\n    {\n        $this-\u003efile = $file;\n    }\n\n    public function upload()\n    {\n        // the file property can be empty if the field is not required\n        if (null === $this-\u003egetFile()) {\n            return;\n        }\n\n        // use the original file name here but you should\n        // sanitize it at least to avoid any security issues\n\n        // move takes the target directory and then the\n        // target filename to move to\n        $this-\u003egetFile()-\u003emove(\n            $this-\u003egetUploadRootDir(),\n            $this-\u003egetFile()-\u003egetClientOriginalName()\n        );\n\n        // set the path property to the filename where you've saved the file\n        $this-\u003epath = $this-\u003egetFile()-\u003egetClientOriginalName();\n\n        // clean up the file property as you won't need it anymore\n        $this-\u003efile = null;\n    }\n}\n```\n\n```php\n\nuse Symfony\\Component\\Form\\Extension\\Core\\Type\\TextType;\nuse Symfony\\Component\\Form\\Extension\\Core\\Type\\FileType;\nuse Symfony\\Component\\Form\\Extension\\Core\\Type\\SubmitType;\n\n$user = User::first();\n\n$form = $this-\u003ecreateFormBuilder($user)\n    -\u003eadd('name', TextType::class)\n    -\u003eadd('file', FileType::class)\n    -\u003eadd('save', SubmitType::class, ['label' =\u003e 'Save user'])\n    -\u003egetForm();\n    \n$form-\u003ehandleRequest($request);\n\nif ($form-\u003eisValid()) {\n    $user-\u003eupload();\n    $user-\u003esave();\n}\n```\n\n## Extending\n\nYou can extend some of the arrays in the ServiceProvider, eg. to add Types, add this to the `register()` method in your own ServiceProvider:\n\n```php\n$this-\u003eapp-\u003eextend('form.types', function($types, $app){\n    $types[] = new CustomType();\n    return $types;\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarryvdh%2Flaravel-form-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbarryvdh%2Flaravel-form-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarryvdh%2Flaravel-form-bridge/lists"}