richardkeep / validate
A simple Laravel 5 package to validate form inputs on the go
Installs: 14
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 1
Forks: 1
Open Issues: 0
Type:beta
Requires
- php: ^7.2
- illuminate/http: ^5.8|^6.0
- illuminate/support: ^5.8|^6.0
- illuminate/validation: ^5.8|^6.0
This package is auto-updated.
Last update: 2024-11-11 20:46:55 UTC
README
Installation
First, pull in the package through Composer.
composer require richardkeep/validate
The package will automatically register its service provider.
To publish the config file to config/richard.php run:
php artisan vendor:publish --provider="Richardkeep\Validate\RichardkeepServiceProvider"
This is the default contents of the configuration:
return [ 'rules' => [ 'password' => 'required|min:3' ] ];
Usage
Place this code in your layout file or anywhere you want to use it.
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> @include('richard::validate')
for example,
<!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>
Ignore CSRF-Token Check
Open app\Http\Middleware\VerifyCsrfTokenCheck.php
add `validate to the URI that should be excluded from CSRF check
/** * The URIs that should be excluded from CSRF verification. * * @var array */ protected $except = [ 'validate' ];
Customizations
Open config\richard.php
and add more validation rules. For example,
'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.
Please try it guys.
Pull requests are highly welcomed.