Stop duplicating code and validations for FormRequests. This package provides reuse of FormRequest rules in a generic way!
You can install the package via composer:
composer require bachilli/laravel-request-rules
Create your main FormRequests with all your validation rules. After that, create unique FormRequests for your controller methods. There is an example of a StoreProductRequest:
public function rules()
{
return RequestRule::resolveRules(
[
'name' => 'required',
],
[
RequestRule::merge(VolumeEntityFormRequest::class, 'volumes.*', 'required|array')->only(['dimensions'])->get(),
RequestRule::merge(ProductEntityFormRequest::class, 'products.*')->except(['price'])->get(),
]);
}
The first array on resolveRules method is exclusive for your FormRequest, the second array is the composed rules, imported from other FormRequests.
There some helper methods available to use when you're importing rules. Below the description of all methods.
In the desired_field_name
you can pass with the suffix .*
to specify an array field.
The optional_validations
are useful when you need an array field and want some validation, like required
.
You can import only rules if you want.
You can do the opposite, importing all rules, except the specified ones.
Not implemented yet.
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email bachilli@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.