1
- # Easily Validate Form Inputs
1
+ # Easily Validate Form Inputs in Laravel
2
2
3
3
## Installation
4
-
5
4
First, pull in the package through Composer.
6
5
7
- ``` js
8
- " require" : {
9
- " richardkeep/validate" : " ~1.0"
10
- }
6
+ ``` bash
7
+ composer require richardkeep/validate
11
8
```
12
9
13
- And then, if using Laravel 5, include the service provider within ` config/app.php ` .
10
+ The package will automatically register its service provider.
11
+
12
+ To publish the config file to config/richard.php run:
13
+
14
+ php artisan vendor: publish --provider="Richardkeep\Validate\RichardkeepServiceProvider"
15
+
16
+ This is the default contents of the configuration:
14
17
15
18
``` php
16
- 'providers' => [
17
- 'Richardkeep\Validate\RichardkeepServiceProvider'
19
+ return [
20
+ 'rules' => [
21
+ 'password' => 'required|min:3'
22
+ ]
18
23
];
19
24
```
20
25
21
- Publish the assets
26
+ ## Usage
27
+ Place this code in your layout file or anywhere you want to use it.
22
28
23
- ``` js
24
- php artisan vendor: publish
29
+ ``` php
30
+ <script src =" https://code.jquery.com/jquery-2.2.4.min.js" ></script >
31
+ @include('richard::validate')
25
32
```
26
33
27
- Place this code below the link of jQuery library
28
-
29
- ``` php
30
- @include('richard::validate');
34
+ for example,
35
+ ``` html
36
+ <!DOCTYPE html>
37
+ <html >
38
+ <head >
39
+ <title >Update Password</title >
40
+ </head >
41
+ <body >
42
+ <div
43
+ <label for =" password" >Password</label >
44
+ <input type =" password" id =" password" class =" form-control" >
45
+ </div >
46
+ </body >
47
+ <script src =" https://code.jquery.com/jquery-2.2.4.min.js" defer ></script >
48
+ @include('richard::validate')
49
+ </html >
31
50
```
32
51
52
+ ## Ignore CSRF-Token Check
33
53
Open ` app\Http\Middleware\VerifyCsrfTokenCheck.php ` add `validate to the URI that should be excluded from CSRF check
54
+
34
55
``` php
35
56
/**
36
57
* The URIs that should be excluded from CSRF verification.
@@ -42,22 +63,20 @@ Open `app\Http\Middleware\VerifyCsrfTokenCheck.php` add `validate to the URI tha
42
63
];
43
64
```
44
65
45
- Open ` config\richard.php ` and add the validation rules. For example,
66
+ ## Customizations
67
+
68
+ Open ` config\richard.php ` and add more validation rules. For example,
46
69
47
70
``` php
48
71
'rules' => [
49
- 'name ' => 'required|min:5 ',
50
- 'email ' => 'required|email ',
72
+ 'password ' => 'required|min:3 ',
73
+ 'name ' => 'required|min:5 ',
51
74
];
52
75
```
53
76
54
77
When a user starts typing, for example their email, the data is validated and the error message is displayed below the text box immediately.
55
78
56
- ![ image1] ( http://s18.postimg.org/rg6iaabwp/email1.png )
57
-
58
- ![ image2] ( http://s24.postimg.org/dyfosc1ad/email2.png )
59
-
60
- In addition, the submit button is disabled if an error is returned.
79
+ ![ Capture] ( https://user-images.githubusercontent.com/3874381/72202629-eae4ca00-3472-11ea-9e40-28e1560720fa.JPG )
61
80
62
81
Please try it guys.
63
82
0 commit comments