dev-master
9999999-devUser input validation
MIT
The Requires
- illuminate/support 4.1.*
- php >=5.4.0
The Development Requires
by Tanel Tammik
laravel validation input rules
Wallogit.com
2017 © Pedro Peláez
User input validation
Rulez provides easy way for setting up input validation rules and validation service. You can add all your rules from one place and later use a facade to validate input., (*2)
Rulez can set sepparate rule for create and update methods. Handy when there's a unique field., (*3)
Require keevitaja/rulez with composer, (*4)
composer require keevitaja/rulez:dev-master, (*5)
Add service provider and alias to app/config/app.php, (*6)
'providers' => array(
'Keevitaja\Rulez\RulezServiceProvider',
),
'aliases' => array(
'Rulez' => 'Keevitaja\Rulez\RulezFacade'
),
Validation rules can be set up in various places, like routes.php, but probably best way would be to create app/rules.php file and require it in the app/start/global.php., (*7)
require app_path().'/rules.php';
Rules can be set sepparately for creation and update. Base rules will apply for both. In the example below, users is the name for the rule set, which can be used later in the controller., (*8)
Rulez::register('users', function($rulez)
{
$rulez->addBase([
'first_name' => 'required|min:2',
'last_name' => 'required|min:2',
'password' => 'required|min:6'
]);
$rulez->addCreate([
'email' => 'required|unique:users|email'
]);
$rulez->addUpdate([
'email' => 'required|unique:users,email,%s|email'
]);
});
If you do not need sepparate rules for create and update, then just use base rules., (*9)
Rulez::validateBase($name, $input), (*10)
Validates base rules., (*11)
Rulez::validateCreate($name, $input), (*12)
Merges create and base rules and validates., (*13)
Rulez::validateUpdate($name, $input, $exclude = false), (*14)
Merges update and base rules, sets the row id for case there's a unique column and validates., (*15)
'users' is the name used with the rule registration in app/rules.php., (*16)
See the example below:, (*17)
$input = Input::all();
if (Rulez::validateUpdate('users', $input, $id))
{
// all ok, lets do the update and redirect
}
// something does not validate, send user back with errors and input
return Redirect::back()->withErrors(Rulez::validationErrors())->withInput();
please follow me @keevitaja, (*18)
User input validation
MIT
laravel validation input rules