xzxzyzyz / laravel-multi-method-form-request
Multi FormRequest For Laravel
v1.3.0
2020-03-05 06:43 UTC
Requires
- php: ^7.2
- illuminate/contracts: ^5.8|^6.0|^7.0
Requires (Dev)
- mockery/mockery: ^1.0
- orchestra/testbench: ^3.8|^4.0|^5.0
- phpunit/phpunit: ^7.5|^8.4|^9.0
This package is auto-updated.
Last update: 2024-12-05 17:53:08 UTC
README
Attaching the validation rules to the request method on FormRequest
.
Rules will be merged when some requests.
Installation
composer require xzxzyzyz/laravel-multi-method-form-request
Usage
Using Xzxzyzyz\Laravel\FormRequest\MultiMethodRule
trait in your FormRequest
class.
use Xzxzyzyz\Laravel\FormRequest\MultiMethodRule; class ExampleRequest extends FormRequest { use MultiMethodRule; // ... }
Methods corresponding to each request method:
And, default rules()
method is always merged.
Example
FormRequest is:
use Xzxzyzyz\Laravel\FormRequest\MultiMethodRule; class ExampleRequest extends FormRequest { use MultiMethodRule; public function rules() { return [ 'default' => 'required' ]; } public function getRules() { return [ 'default' => 'it_is_get_rule', 'get' => 'required' ]; } public function createRules() { return [ 'default' => 'it_is_create_rule', 'post' => 'required' ]; } public function updateRules() { return [ 'default' => 'it_is_update_rule', 'put' => 'required' ]; } public function deleteRules() { return [ 'default' => 'it_is_delete_rule', 'delete' => 'required' ]; } }
If GET
request, Return rules is:
If POST
request, Return rules is:
If PUT
request, Return rules is:
If DELETE
request, Return rules is: