Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xzxzyzyz/laravel-multi-method-form-request
https://github.com/xzxzyzyz/laravel-multi-method-form-request
form-request formreques laravel
Last synced: 28 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/xzxzyzyz/laravel-multi-method-form-request
- Owner: xzxzyzyz
- License: mit
- Created: 2018-10-05T03:25:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-05T06:46:08.000Z (almost 5 years ago)
- Last Synced: 2024-11-25T14:52:11.872Z (about 1 month ago)
- Topics: form-request, formreques, laravel
- Language: PHP
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Multi Method Form Request
[![CircleCI](https://circleci.com/gh/xzxzyzyz/laravel-multi-method-form-request.svg?style=svg)](https://circleci.com/gh/xzxzyzyz/laravel-multi-method-form-request)
[![Latest Stable Version](https://poser.pugx.org/xzxzyzyz/laravel-multi-method-form-request/version)](https://packagist.org/packages/xzxzyzyz/laravel-multi-method-form-request)
[![License](https://poser.pugx.org/xzxzyzyz/laravel-multi-method-form-request/license)](https://packagist.org/packages/xzxzyzyz/laravel-multi-method-form-request)Attaching the validation rules to the request method on `FormRequest`.
Rules will be merged when some requests.
## Installation
```bash
composer require xzxzyzyz/laravel-multi-method-form-request
```## Usage
Using `Xzxzyzyz\Laravel\FormRequest\MultiMethodRule` trait in your `FormRequest` class.
```php
use Xzxzyzyz\Laravel\FormRequest\MultiMethodRule;class ExampleRequest extends FormRequest
{
use MultiMethodRule;
// ...
}
```Methods corresponding to each request method:
Request Method | Rule Method
:---------|:----------
GET | getRules()
POST | createRules()
PUT | updateRules()
DELETE | deleteRules()
And, default `rules()` method is always merged.
### ExampleFormRequest is:
```php
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:
name | rules
:--------|:----------
default | required, it_is_get_rule
get | requiredIf `POST` request, Return rules is:
name | rules
:--------|:----------
default | required, it_is_create_rule
post | requiredIf `PUT` request, Return rules is:
name | rules
:--------|:----------
default | required, it_is_update_rule
put | requiredIf `DELETE` request, Return rules is:
name | rules
:----------|:----------
default | required, it_is_delete_rule
delete | required