-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example.php
75 lines (55 loc) · 2.11 KB
/
Example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/*
EXPLANATION:
function trans() is a wrapped function arround the illuminate/translation
It basically just translates from a file a given string, in this case it translates from validation.php file.
Which, can be found in this repository too... Check the illuminate/translation for more info on this
Below is a simple registration form validation
*/
$localisedResponses = array(
'empty' => trans('validation.empty'),
'badFormat' => trans('validation.badFormat'),
'length' => trans('validation.length'),
'minMax' => trans('validation.minMax'),
'int' => trans('validation.int'),
'float' => trans('validation.float'),
'alpha' => trans('validation.alpha'),
'alphanum' => trans('validation.alphanum'),
'whiteSpace' => trans('validation.whiteSpace'),
'url' => trans('validation.url'),
'uri' => trans('validation.uri'),
'bool' => trans('validation.bool'),
'email' => trans('validation.email'),
'equal' => trans('validation.equal')
);
$validation = new Validate($localisedResponses);
$validation->setField('username')
->setName(trans('signup.form.username'))
->setValue($request->getParam('username'))
->notEmpty()
->alpha()
->length(2, 20);
$validation->setField('email')
->setName(trans('signup.form.email'))
->setValue($request->getParam('email'))
->notEmpty()
->email()
->custom(function($data) {
$available = User::where('email', $data->value)->first() ? false : true;
if(!$available) {
$data->addError(trans('validation.custom.email_taken'));
}
});
$validation->setField('password')
->setName(trans('signup.form.password'))
->setValue($request->getParam('password'))
->notEmpty()
->length(6, 20);
$validation->setField('password_repeat')
->setName(trans('signup.form.passwordAgain'))
->setValue($request->getParam('password_repeat'))
->equal('password', $request->getParam('password'), trans('signup.form.password'));
if($validation->failed()) {
echo 'We\'ve got some errors boys!';
}
echo 'Ayyy Lmao!!!';