Wallogit.com
2017 © Pedro Peláez
A simple Laravel 5 package to validate form inputs on the go
First, pull in the package through Composer., (*1)
composer require richardkeep/validate
The package will automatically register its service provider., (*2)
To publish the config file to config/richard.php run:, (*3)
php artisan vendor:publish --provider="Richardkeep\Validate\RichardkeepServiceProvider", (*4)
This is the default contents of the configuration:, (*5)
return [
'rules' => [
'password' => 'required|min:3'
]
];
Place this code in your layout file or anywhere you want to use it., (*6)
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
@include('richard::validate')
for example,, (*7)
<!DOCTYPE html>
<html>
<head>
<title>Update Password</title>
</head>
<body>
<div
<label for="password">Password</label>
<input type="password" id="password" class="form-control">
</div>
</body>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" defer></script>
@include('richard::validate')
</html>
Open app\Http\Middleware\VerifyCsrfTokenCheck.php add `validate to the URI that should be excluded from CSRF check, (*8)
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
'validate'
];
Open config\richard.php and add more validation rules. For example,, (*9)
'rules' => [
'password' => 'required|min:3',
'name' => 'required|min:5',
];
When a user starts typing, for example their email, the data is validated and the error message is displayed below the text box immediately., (*10)
, (*11)
Please try it guys., (*12)
Pull requests are highly welcomed., (*13)