xzxzyzyz/laravel-multi-method-form-request

Multi FormRequest For Laravel

v1.3.0 2020-03-05 06:43 UTC

This package is auto-updated.

Last update: 2024-12-05 17:53:08 UTC


README

CircleCI Latest Stable Version License

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: