{"id":16353141,"url":"https://github.com/lorisleiva/request-controller","last_synced_at":"2025-03-21T00:31:15.727Z","repository":{"id":62519084,"uuid":"313082538","full_name":"lorisleiva/request-controller","owner":"lorisleiva","description":"Use FormRequests as invokable controllers","archived":false,"fork":false,"pushed_at":"2020-11-17T10:27:03.000Z","size":29,"stargazers_count":28,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-17T19:13:10.173Z","etag":null,"topics":["controllers","form-request","laravel"],"latest_commit_sha":null,"homepage":"","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/lorisleiva.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"lorisleiva"}},"created_at":"2020-11-15T17:14:48.000Z","updated_at":"2022-11-17T15:59:55.000Z","dependencies_parsed_at":"2022-11-02T13:30:52.289Z","dependency_job_id":null,"html_url":"https://github.com/lorisleiva/request-controller","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorisleiva%2Frequest-controller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorisleiva%2Frequest-controller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorisleiva%2Frequest-controller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorisleiva%2Frequest-controller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lorisleiva","download_url":"https://codeload.github.com/lorisleiva/request-controller/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244717366,"owners_count":20498282,"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":["controllers","form-request","laravel"],"created_at":"2024-10-11T01:28:56.272Z","updated_at":"2025-03-21T00:31:15.441Z","avatar_url":"https://github.com/lorisleiva.png","language":"PHP","readme":"# Use FormRequests as invokable controllers\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/lorisleiva/request-controller.svg)](https://packagist.org/packages/lorisleiva/request-controller)\n[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/lorisleiva/request-controller/Tests?label=tests)](https://github.com/lorisleiva/request-controller/actions?query=workflow%3ATests+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/lorisleiva/request-controller.svg)](https://packagist.org/packages/lorisleiva/request-controller)\n\nAren't you tired of having to create a `FormRequest` class for almost every invokable `Controller` you create?\n\nIt turns out, [with a few tweaks](https://lorisleiva.com/if-formrequests-and-invokable-controllers-had-a-baby/), you can use a `FormRequest` class as a controller.\n\nThis package provides only one class: a `RequestController` class that extends the `FormRequest` class we all know and adapt it slightly so it works as an invokable `Controller`.\n\n## Installation\n\n```bash\ncomposer require lorisleiva/request-controller\n```\n\n## Usage\n\n``` php\nclass MyController extends RequestController\n{\n    public function middleware()\n    {\n        return [];\n    }\n\n    public function authorize()\n    {\n        return true;\n    }\n\n    public function rules()\n    {\n        return [];\n    }\n\n    public function __invoke()\n    {\n        // ...\n    }\n}\n```\n\nNote that the `middleware`, `authorize` and `rules` methods are all optional and default to the value displayed in the example.\n\nSince `RequestController` extends `FormRequest`, you have access to all the methods you are used to, like:\n- `$this-\u003eget($attribute)` — To access a request attribute.\n- `$this-\u003eroute($attribute)` — To access a route parameter.\n- `$this-\u003evalidated()` — To access the validated data.\n- `$this-\u003euser()` — To access the user.\n- Etc.\n\nSimilarly, you can override the same `FormRequest` methods you are used to, in order to customize the validation logic:\n- `attributes()` — To provide user-friendly names to your attributes.\n- `message()` — To customize your validation messages.\n- `withValidator()` — To extends the current validator.\n- `validator()` — To take full control over the validator created.\n- Etc.\n\nEnjoy! ✨\n","funding_links":["https://github.com/sponsors/lorisleiva"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Florisleiva%2Frequest-controller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Florisleiva%2Frequest-controller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Florisleiva%2Frequest-controller/lists"}