{"id":14986022,"url":"https://github.com/statix-php/laravel-form-actions","last_synced_at":"2026-01-04T06:45:47.799Z","repository":{"id":189975726,"uuid":"676717860","full_name":"statix-php/laravel-form-actions","owner":"statix-php","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-25T12:39:12.000Z","size":71,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-03T08:03:24.770Z","etag":null,"topics":[],"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/statix-php.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2023-08-09T21:06:21.000Z","updated_at":"2024-04-15T13:37:53.396Z","dependencies_parsed_at":"2024-04-15T13:37:51.550Z","dependency_job_id":"5ce995ce-7029-4aef-a551-027550bcbda6","html_url":"https://github.com/statix-php/laravel-form-actions","commit_stats":null,"previous_names":["statix-php/laravel-form-actions"],"tags_count":3,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statix-php%2Flaravel-form-actions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statix-php%2Flaravel-form-actions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statix-php%2Flaravel-form-actions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statix-php%2Flaravel-form-actions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/statix-php","download_url":"https://codeload.github.com/statix-php/laravel-form-actions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244826634,"owners_count":20516797,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-09-24T14:12:09.157Z","updated_at":"2026-01-04T06:45:47.773Z","avatar_url":"https://github.com/statix-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Form Actions\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/statix-php/laravel-form-actions.svg?style=flat-square)](https://packagist.org/packages/statix-php/laravel-form-actions)\n[![Total Downloads](https://img.shields.io/packagist/dt/statix-php/laravel-form-actions.svg?style=flat-square)](https://packagist.org/packages/statix-php/laravel-form-actions)\n\nLaravel Form Actions combines the best features of Spatie's Laravel Data and Laravel's Form Requests, resulting in a powerful and efficient package that simplifies form handling in your Laravel applications.\n\n## Installation\n\nYou can easily install this package using Composer by running the following command. For more details, visit the [Packagist page](https://packagist.org/packages/statix-php/laravel-form-actions).\n\n```bash\ncomposer require statix-php/laravel-form-actions\n```\n\n## Creating `FormActions`\n\nSimiliar to [Laravel Form Requests](https://laravel.com/docs/validation#form-request-validation), you can create a new `FormAction` using Artisan with the following command:\n\n```bash\nphp artisan make:form-action ActionName\n```\n\nThis command will generate a ActionName class in the app\\Actions directory. The initial content of the class is as follows:\n\n```php\n\u003c?php \n\nnamespace App\\Actions;\n\nuse Statix\\FormAction\\FormAction;\n\nclass ActionName extends FormAction\n{\n    public function authorized(): bool\n    {\n        return true;\n    }\n\n    public function handle()\n    {\n        // Do cool things, tell people - Aaron Francis\n    }\n}\n```\n\nOnce the action is created, you can start building it out. Let's demonstrate how to use an action to create a new `User`.\n\n```php\n\u003c?php \n\nnamespace App\\Actions;\n\nuse App\\Models\\User;\nuse Statix\\FormAction\\FormAction;\nuse Statix\\FormAction\\Validation\\Rules;\n\nclass ActionName extends FormAction\n{\n    #[Rules(['required', 'string', 'min:3', 'max:255'])] \n    public $name;\n\n    #[Rules(['email', 'unique:users,email'])] \n    public string $email;\n\n    public ?string $timezone;\n\n    public function authorized(): bool \n    {\n        return true;\n    }\n\n    public function handle(): User\n    {\n        return User::create([\n            'name' =\u003e $this-\u003ename,\n            'email' =\u003e $this-\u003eemail,\n            'timezone' =\u003e $this-\u003etimezone ?? 'UTC',\n        ]);\n    }\n}\n```\n\nWith the action in place, let's integrate it into our routes.\n\n```php\n// routes/web.php\n\nuse App\\Actions\\ActionName;\n\nRoute::post('/register', function(ActionName $action) {\n\n    $user = $action-\u003ehandle();\n\n    auth()-\u003elogin($user);\n\n    return redirect()-\u003eroute('dashboard');\n});\n```\n\nNo manual authorization or validation calls are required. Just like Laravel `FormRequest`, the actions automatically handle authorization and validation when they're resolved from the container. (This behavior can be disabled).\n\nAwesome, so now let's write some tests for this action!\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease reach out to me directly for any potential security vulnerabilities.\n\n## Credits\n\n- [Wyatt Castaneda](https://github.com/statix-php)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatix-php%2Flaravel-form-actions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstatix-php%2Flaravel-form-actions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatix-php%2Flaravel-form-actions/lists"}