Download the PHP package lorisleiva/request-controller without Composer
On this page you can find all versions of the php package lorisleiva/request-controller. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lorisleiva/request-controller
More information about lorisleiva/request-controller
Files in lorisleiva/request-controller
Package request-controller
Short Description FormRequest and InvokableController just had a baby
License MIT
Homepage https://github.com/lorisleiva/request-controller
Informations about the package request-controller
Use FormRequests as invokable controllers
Aren't you tired of having to create a FormRequest
class for almost every invokable Controller
you create?
It turns out, with a few tweaks, you can use a FormRequest
class as a controller.
This 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
.
Installation
Usage
Note that the middleware
, authorize
and rules
methods are all optional and default to the value displayed in the example.
Since RequestController
extends FormRequest
, you have access to all the methods you are used to, like:
$this->get($attribute)
— To access a request attribute.$this->route($attribute)
— To access a route parameter.$this->validated()
— To access the validated data.$this->user()
— To access the user.- Etc.
Similarly, you can override the same FormRequest
methods you are used to, in order to customize the validation logic:
attributes()
— To provide user-friendly names to your attributes.message()
— To customize your validation messages.withValidator()
— To extends the current validator.validator()
— To take full control over the validator created.- Etc.
Enjoy! ✨