Download the PHP package amirhs712/rule-builder without Composer
On this page you can find all versions of the php package amirhs712/rule-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download amirhs712/rule-builder
More information about amirhs712/rule-builder
Files in amirhs712/rule-builder
Package rule-builder
Short Description Validation Rule Builder for Laravel
License MIT
Informations about the package rule-builder
Nope
Nope is a validation rule builder for laravel inspired by Yup
for javascript.
With Nope
you can generate rules more fluently, I've also copied rules description from laravel official website and hard coded them into Nope,
so you can have access to documentations easily.
Some functionalities have been extended for validation rules, for example you can pass Carbon instances to date validation rules like after
.
Installation
Require this package with composer using the following command:
Usage
I recommend using nope()
global helper for warning-free and complete ide-inspection.
Also you can use Amirhs712\RuleBuilder\Nope
class instead.
We use get()
to get output as an array, alternatively you can use toString()
to return the output as a pipe separated string.
toString
andget
support a required status ranging from-2
to1
.- 1 => call
required
rule - 0 => do nothing (default)
- -1 => call
sometimes
rule - -2 => call
sometimes
&nullable
rules
- 1 => call
Date Rules with Carbon
You can pass a carbon instance to the following date rules: after
, afterOrEqual
, dateEquals
,before
, beforeOrEqual
Min / Max Helpers
These methods allow you to set min and / or max arguments manually.
Raw rules
You can use raw(string|array)
to add raw string rules or validation objects.
- Note: You cannot call
toString
method if you have validation objects. Doing so will result in an error.
Conditional rules
You can use when
method to add rules conditionally.
Laravel constraint builders
in
, notIn
, dimensions
, exists
, unique
methods support both their relative constraint builders and,
their default values.
Templates
You can build and define your own rule templates.
Coming soon!
Undefined methods
Right now there are no limitations for method calls (I could not find a reason to do so), for example you can do
Alternatives
You can check this package as an alternative, I've implemented some ideas from this package and merged them into my own solution.
Feedback
Please feel free to open up an issue, or a Pull Request if you have any suggestions.