{"id":45161703,"url":"https://github.com/tsommie/laravel-form-processor","last_synced_at":"2026-02-20T06:02:55.241Z","repository":{"id":56939794,"uuid":"126548038","full_name":"tsommie/laravel-form-processor","owner":"tsommie","description":"An easy way to process multiple form requests from one controller method.","archived":false,"fork":false,"pushed_at":"2018-06-03T13:06:44.000Z","size":46,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-13T00:38:45.615Z","etag":null,"topics":["form","laravel","lumen","processing"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tsommie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-23T23:18:47.000Z","updated_at":"2024-04-13T00:38:45.616Z","dependencies_parsed_at":"2022-08-21T06:50:12.120Z","dependency_job_id":null,"html_url":"https://github.com/tsommie/laravel-form-processor","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/tsommie/laravel-form-processor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsommie%2Flaravel-form-processor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsommie%2Flaravel-form-processor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsommie%2Flaravel-form-processor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsommie%2Flaravel-form-processor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tsommie","download_url":"https://codeload.github.com/tsommie/laravel-form-processor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsommie%2Flaravel-form-processor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29642907,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-20T05:21:04.652Z","status":"ssl_error","status_checked_at":"2026-02-20T05:21:04.238Z","response_time":59,"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":["form","laravel","lumen","processing"],"created_at":"2026-02-20T06:02:52.274Z","updated_at":"2026-02-20T06:02:55.236Z","avatar_url":"https://github.com/tsommie.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 1. Laravel Form Processor\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\nThis is a library that was inspired by one of the Laravel project i worked on that required me to run over half a dozen different updates on one particular `Model` or `Entity`. I could have easily created a different controller method and route for each request but it made my `web.php` file bloated and so was my `controller` and am a big fan of keeping my routes file as thin as possible and my controllers looking the same as it was when i first ran the `artisan make:controller` command, containing nothing else but the `index, store, show, edit, update and destroy` methods. So i decided to look for a way to process different but similar (maybe its to update the same model or sending the request to the same controller) form requests from one controller method and `Laravel Form Processor` was what i could come up with.\n\n\u003e **_Note: There might be another or other ways more intuitive to achieve this same results but at the time and giving my skill level in PHP and Laravel this looked like a really good idea to me, it's just my opinion so feel free to consult a pro._**\n\n**This is a package for Laravel 5.x and Lumen 5.x**\n\n[![Laravel 5](http://sammyk.s3.amazonaws.com/open-source/laravel-facebook-sdk/laravel-5.png)](http://laravel.com/docs)\n\n[![Lumen 5](http://sammyk.s3.amazonaws.com/open-source/laravel-facebook-sdk/lumen-5.png)](https://lumen.laravel.com/docs)\n\n\u003c!-- TOC --\u003e\n\n- [1. Laravel Form Processor](#1-laravel-form-processor)\n    - [1.1. Setting up](#11-setting-up)\n        - [1.1.1. Installation on Lumen 5.x and Laravel 5.x.](#111-installation-on-lumen-5x-and-laravel-5x)\n        - [1.1.2. Installation on Lumen and Laravel 5.4 and below.](#112-installation-on-lumen-and-laravel-54-and-below)\n            - [1.1.2.1. Service Provider](#1121-service-provider)\n            - [1.1.2.2. Facade (optional)](#1122-facade-optional)\n        - [1.1.3. Publishing config file.](#113-publishing-config-file)\n        - [1.1.4. Configure paths for generated processes](#114-configure-paths-for-generated-processes)\n    - [1.2. Usage](#12-usage)\n        - [1.2.1. Creating a form Process class](#121-creating-a-form-process-class)\n        - [1.2.2. Setting up the controller to receive our process.](#122-setting-up-the-controller-to-receive-our-process)\n            - [1.2.2.1. Using LaravelFormProcessorInterface](#1221-using-laravelformprocessorinterface)\n            - [1.2.2.2. Using LaravelFormProcessorFacade](#1222-using-laravelformprocessorfacade)\n    - [1.3. Security Vulnerabilities](#13-security-vulnerabilities)\n    - [1.4. License](#14-license)\n\n\u003c!-- /TOC --\u003e\n\n## 1.1. Setting up\n### 1.1.1. Installation on Lumen 5.x and Laravel 5.x.\nAdd the Laravel Form Processor package to your `composer.json` file.\n\n```\ncomposer require ac-developers/laravel-form-processor\n```\n\n\u003e **Auto-discovery:** Is supported in Laravel Form Processor [auto-discovery](https://medium.com/@taylorotwell/package-auto-discovery-in-laravel-5-5-ea9e3ab20518) for Laravel 5.5 and greater.\n\n### 1.1.2. Installation on Lumen and Laravel 5.4 and below.\n#### 1.1.2.1. Service Provider\n\nIn your app config, add the `LaravelFormProcessorServiceProvider` to the providers array.\n\n```php\n'providers' =\u003e [\n    AcDevelopers\\LaravelFormProcessor\\LaravelFormProcessorServiceProvider::class,\n    ];\n```\n\nFor **Lumen**, add the provider to your `bootstrap/app.php` file.\n\n```php\n$app-\u003eregister(AcDevelopers\\LaravelFormProcessor\\LaravelFormProcessorServiceProvider::class);\n```\n\n#### 1.1.2.2. Facade (optional)\n\nIf you want to make use of the facade, add it to the aliases array in your app config.\n\n```php\n'aliases' =\u003e [\n    'LaravelFormProcessorFacade' =\u003e AcDevelopers\\LaravelFormProcessor\\LaravelFormProcessorFacade::class,\n    ];\n```\n### 1.1.3. Publishing config file.\nTo publish the config file to `config/laravel-form-processor.php` run:\n\n```\nphp artisan vendor:publish --provider=\"AcDevelopers\\LaravelFormProcessor\\LaravelFormProcessorServiceProvider\"\n```\n\n### 1.1.4. Configure paths for generated processes\nTo change the paths of saving the generated processes, you need to configure their namespaces in a configuration file `config/laravel-form-processor.php`.\n\n```\n\nreturn [\n    /*\n    |--------------------------------------------------------------------------\n    | Default namespaces for the classes\n    |--------------------------------------------------------------------------\n    */\n    'namespaces' =\u003e [\n        'process'   =\u003e 'App\\Processes',\n        'model'        =\u003e 'App\\\\',\n    ],\n];\n```\n\nAnd you�re good to go.\n\n## 1.2. Usage\n\n### 1.2.1. Creating a form Process class\nLet's assume you have a model in your Laravel app called `Article` and you wish to run an update on it to change its `published field` from `false` to `true`, after configuring the directory you wish to place you�re Processes in, run:\n```\nphp artisan generate:process PublishArticleProcess --model=Article\n```\nthis will create a form process class tied to a `Model` in this case `Article` (of course specifying a model is optional).\nIf the process directory path is left as it is your processes will be stored in a `App\\Processes` directory. Don�t worry, if this doesn't exist one will be created for you.\n\n```\nclass PublishArticleProcess extends LaravelFormProcess implements LaravelFormProcessableInterface\n{\n    /**\n     * PublishArticleProcess constructor.\n     * @param \\Illuminate\\Http\\Request $request\n     * @param \\App\\Article $article\n     */\n    public function __construct(Request $request, Article $article)\n    {\n        $this-\u003erequest = $request;\n        $this-\u003emodel = $article;\n    }\n\n    /**\n     * @return \\Illuminate\\Http\\Response\n     */\n    public function handle()\n    {\n        //\n    }\n}\n```\nAfter the Process class has been generated, all the logic that is required to update the `Article published field` will go into the `handle` method.\n\n\u003e **_Tip! You�re processes should as much as possible look and respond like the controller methods they are been used in. e.g compare the constructor of the process generated above with the `update` method on a resourceful `ArticleController`._**\n\n```\nclass PublishArticleProcess extends LaravelFormProcess implements LaravelFormProcessableInterface\n{\n    protected $request;\n\n    protected $article;\n\n    /**\n     * PublishArticleProcess constructor.\n     * @param \\Illuminate\\Http\\Request $request\n     * @param \\App\\Article $article\n     */\n    public function __construct(Request $request, Article $article)\n    {\n        $this-\u003erequest = $request;\n        $this-\u003earticle = $article;\n    }\n\n    /**\n     * @return \\Illuminate\\Http\\Response\n     */\n    public function handle()\n    {\n        // Perform validation using Laravel's ValidatesRequests trait\n        $this-\u003evalidate($this-\u003erequest, ['published' =\u003e 'required']);\n\n        // Update the model\n        $result = $this-\u003earticle-\u003eupdate($this-\u003erequest-\u003eall());\n\n        // Return to any desired location if update was successful. \n        if ($result) {\n            return redirect()-\u003eroute('articles.show', ['id' =\u003e $this-\u003earticle-\u003eid])\n                -\u003ewith('status', 'Article was updated successfully.');\n        }\n\n        // Return back if not.\n        return back()-\u003ewithErrors(['Unable to update this article.']);\n    }\n}\n```\nAlthough this is a simple use case, a lot of things can be done here like dispatching jobs, firing events, authorizations and so on, thanks to the use of Laravel's `AuthorizesRequests, DispatchesJobs, ValidatesRequests` extended by the abstract `LaravelFormProcess` class you can work in a process like you would in a Laravel controller. The important thing to take away from this is that all `Process handle` methods MUST only return a `Response` and not a `View`.\n\n### 1.2.2. Setting up the controller to receive our process.\nWhen it comes to where to put your process in a controller it only comes down to what category your actions fall into in the `CRUD` classification.\nIn our case this would be the `U` in `CRUD` which stands for `update`.\n\nNow a lot of you would be asking \"why else would you need to place a `Processor` in any other controller method aside from the `update` method\"? \n\nWell imaging you have two delete buttons in your `view`, one for the admins and the other for the superuser, now when an admin decides to delete an article you as a superuser would want to have a finall say in the matter. So when processing a delete action for an admin a `soft delete` will be in order, followed by a notification letting the superuser know about the admin's intention to delete an article, now when the superuser decide to go along with their decision he/she can now perform a delete action that would permanently remove the article from the database.\n\n#### 1.2.2.1. Using LaravelFormProcessorInterface\nNow in your `update` method inside of you�re `ArticleController` class you would inject the `LaravelFormProcessorInterface` like this:\n```\n    /**\n     * Update the specified resource in storage.\n     *\n     * @param  \\Illuminate\\Http\\Request  $request\n     * @param  \\App\\Article $article\n     * @param LaravelFormProcessorInterface $laravelFormProcessorInterface\n     * @return \\Illuminate\\Http\\Response\n     */\n    public function update(Request $request, Article $article, LaravelFormProcessorInterface $formProcessorInterface)\n    {\n        $process = $formProcessorInterface-\u003eretrieveProcessFromFormField($request-\u003eget('_prKey'))\n\n        return $formProcessorInterface-\u003erun(new $process($request, $article));\n    }\n```\n\n#### 1.2.2.2. Using LaravelFormProcessorFacade\nYou can use the `LaravelFormProcessorFacade` if you're more comfortable with Facades like the example shows below.\n\n```\n/**\n     * Update the specified resource in storage.\n     *\n     * @param  \\Illuminate\\Http\\Request  $request\n     * @param  \\App\\Article $article\n     * @return \\Illuminate\\Http\\Response\n     */\n    public function update(Request $request, Article $article)\n    {\n        $process = LaravelFormProcessorFacade::retrieveProcessFromFormField($request-\u003eget('_prKey'))\n\n        return LaravelFormProcessorFacade::run(new $process($request, $article));\n    }\n```\n\nand then in the form you wish to process you will use a `@renderProcess` directive provided with the package to point to the Process class that will be used to run or handle the form request.\n\n```\n\u003cform action=\"route('articles.update', ['id' =\u003e article-\u003eid])\" method=\"POST\"\u003e\n    @csrf\n    @method('PATCH')}}\n\n    @renderProcess(\\App\\Process\\ArticlePublishProcess)\n    \n    \u003cdiv class=\"d-block my-3\"\u003e\n        \u003cdiv class=\"custom-control custom-radio\"\u003e\n            \u003cinput name=\"published\" checked=\"\" type=\"radio\" value=\"true\"\u003e\u003clabel\u003ePublish\u003c/label\u003e\n        \u003c/div\u003e\n        \u003cdiv class=\"custom-control custom-radio\"\u003e\n            \u003cinput name=\"published\" type=\"radio\" value=\"false\"\u003e\u003clabel\u003eUnpublish\u003c/label\u003e\n        \u003c/div\u003e\n    \u003c/div\u003e\n\u003c/form\u003e\n```\n\u003e The `renderProcess` method available on the `LaravelFormProcessorFacade` will achieve the same goals as the `@renderProcess` directive so feel free to use any of them as you wish.\n\n\nAnd you�re done, now unless you have an issue with your code everything should run just fine.\n\n## 1.3. Security Vulnerabilities\nIf you discover a security vulnerability within Laravel Form Processor, please send an e-mail to Anitche Chisom via anitchec.dev@gmail.com. All security vulnerabilities will be promptly addressed.\n\n## 1.4. License\nThe Laravel Form Processor is open-sourced software licensed under the [MIT](LICENSE) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsommie%2Flaravel-form-processor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftsommie%2Flaravel-form-processor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsommie%2Flaravel-form-processor/lists"}