Skip to content

richardkeep/validate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 

Repository files navigation

Easily Validate Form Inputs in Laravel

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.

Capture

Please try it guys.

Pull requests are highly welcomed.