Skip to content

Commit 437bc0c

Browse files
committed
Initial commit
0 parents  commit 437bc0c

13 files changed

+756
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Composer
2+
/composer.lock
3+
/vendor/*
4+
5+
# PHPUnit
6+
/.phpunit.result.cache
7+
8+
# Other
9+
.idea/

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 Sebastian Sulinski
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Laravel validation wrapper
2+
3+
This package, when used with form requests expecting Json, generates Json response with the errors representing rule index rather than message for a failed rule i.e.
4+
5+
```php
6+
[
7+
'message' => 'The given data was invalid.',
8+
'errors' => [
9+
'name' => ['required', 'max'],
10+
'email' ['email'],
11+
],
12+
]
13+
```
14+
15+
If request is not expecting Json - default Laravel redirect response with errors stored in session is being used.
16+
17+
Using this package with front and back end validation allows us having validation message directly with the form and only reveal the relevant one based on which rule failed the validation.
18+
19+
## Installation
20+
21+
```bash
22+
composer require sebastiansulinski/laravel-validation
23+
```
24+
25+
## Service Provider and Facade
26+
27+
Replace default `Illuminate\Validation\ValidationServiceProvider::class` provider in `config/app.php`:
28+
29+
30+
```php
31+
<?php
32+
33+
return [
34+
...
35+
36+
'providers' => [
37+
...
38+
// Illuminate\Validation\ValidationServiceProvider::class, - remove
39+
SSD\LaravelValidation\ValidationServiceProvider::class,
40+
41+
],
42+
];
43+
```

composer.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "sebastiansulinski/laravel-validation",
3+
"description": "Validation wrapper for Laravel 5.8+",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "Sebastian Sulinski",
8+
"email": "[email protected]"
9+
}
10+
],
11+
"minimum-stability": "stable",
12+
"autoload": {
13+
"psr-4": {
14+
"SSD\\LaravelValidation\\": "src"
15+
}
16+
},
17+
"autoload-dev": {
18+
"psr-4": {
19+
"SSDTest\\": "tests/"
20+
}
21+
},
22+
"require-dev": {
23+
"orchestra/testbench": "^3.8"
24+
},
25+
"require": {
26+
"php": "^7.1.3",
27+
"laravel/framework": "5.8.*"
28+
}
29+
}

phpunit.xml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="true">
11+
<testsuites>
12+
<testsuite name="Feature">
13+
<directory suffix="Test.php">./tests</directory>
14+
</testsuite>
15+
</testsuites>
16+
<filter>
17+
<whitelist processUncoveredFilesFromWhitelist="true">
18+
<directory suffix=".php">./src</directory>
19+
</whitelist>
20+
</filter>
21+
<php>
22+
<env name="DB_CONNECTION" value="testing"/>
23+
</php>
24+
</phpunit>

0 commit comments

Comments
 (0)