Skip to content

Commit 7107beb

Browse files
committed
wip
1 parent 33acf03 commit 7107beb

File tree

9 files changed

+64
-79
lines changed

9 files changed

+64
-79
lines changed

composer.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,23 @@
77
"name": "Richard Keep"
88
}
99
],
10+
"require": {
11+
"php": "^7.2",
12+
"illuminate/validation": "^5.8|^6.0",
13+
"illuminate/http": "^5.8|^6.0",
14+
"illuminate/support": "^5.8|^6.0"
15+
},
1016
"autoload": {
1117
"psr-4": {
12-
"RichardKeep\\Validate\\": "src/"
18+
"Richardkeep\\Validate\\": "src/"
19+
}
20+
},
21+
"extra": {
22+
"laravel": {
23+
"providers": [
24+
"Richardkeep\\Validate\\RichardkeepServiceProvider"
25+
]
1326
}
1427
},
15-
"minimum-stability": "dev",
16-
"require": {}
28+
"minimum-stability": "dev"
1729
}

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ And then, if using Laravel 5, include the service provider within `config/app.ph
1414

1515
```php
1616
'providers' => [
17-
'RichardKeep\Validate\RichardKeepServiceProvider'
17+
'Richardkeep\Validate\RichardkeepServiceProvider'
1818
];
1919
```
2020

src/CustomValidations/ValidationExtended.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/RichardKeepServiceProvider.php

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
1-
<?php namespace RichardKeep\Validate;
1+
<?php
22

3-
use Illuminate\Support\ServiceProvider;
4-
use RichardKeep\Validate\CustomValidations\ValidationExtended;
5-
6-
class RichardKeepServiceProvider extends ServiceProvider {
3+
namespace Richardkeep\Validate;
74

8-
/**
9-
* Bootstrap the application services.
10-
*
11-
* @return void
12-
*/
13-
public function boot()
14-
{
15-
$this->loadViewsFrom(__DIR__.'/views','richard');
5+
use Illuminate\Support\ServiceProvider;
6+
use Richardkeep\Validate\CustomValidations\ValidationExtended;
167

17-
$this->app->validator->resolver(function ($translator, $data, $rules, $messages = array(), $customAttributes = array()){
18-
return new ValidationExtended($translator, $data, $rules, $messages, $customAttributes);
19-
});
8+
class RichardkeepServiceProvider extends ServiceProvider
9+
{
2010

21-
$this->publishes([
22-
__DIR__.'/views/app.js' => public_path("js/richardkeep/app.js"),
23-
__DIR__.'/config/richard.php' => base_path("config/richard.php"),
24-
]);
25-
}
11+
/**
12+
* Bootstrap the application services.
13+
*
14+
* @return void
15+
*/
16+
public function boot()
17+
{
18+
$this->loadViewsFrom(__DIR__.'/resources/views', 'richard');
2619

27-
/**
28-
* Register the application services.
29-
*
30-
* @return void
31-
*/
32-
public function register()
33-
{
34-
include __DIR__.'/routes.php';
35-
}
20+
$this->publishes([
21+
__DIR__.'/resources/js/app.js' => public_path("js/richardkeep/app.js"),
22+
__DIR__.'/config/richard.php' => base_path("config/richard.php"),
23+
]);
24+
}
3625

26+
/**
27+
* Register the application services.
28+
*
29+
* @return void
30+
*/
31+
public function register()
32+
{
33+
include __DIR__.'/routes.php';
34+
}
3735
}

src/ValidationController.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
<?php namespace RichardKeep\Validate;
1+
<?php
2+
3+
namespace Richardkeep\Validate;
24

35
use Validator;
46
use Illuminate\Http\Request;
57

68
class ValidationController
79
{
8-
// Validate a POST request
9-
10-
public function validate(Request $request)
11-
{
12-
13-
$field = preg_replace('/-/', '_', $request->get('field'));
14-
15-
$data = [
16-
"{$field}" => $request->get('data')
17-
];
10+
public function __invoke(Request $request)
11+
{
12+
$field = preg_replace('/-/', '_', $request->field);
1813

19-
$v = Validator::make($data, config('richard.rules'));
20-
21-
return json_encode( $v->errors()->first( $field ) );
22-
}
14+
return json_encode(
15+
Validator::make([
16+
"{$field}" => $request->data
17+
], config('richard.rules'))
18+
->errors()
19+
->first($field)
20+
);
21+
}
2322
}

src/config/richard.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
<?php
22

33
return [
4-
/*
4+
/*
55
|--------------------------------------------------------------------------
66
| Validation Rules
77
|--------------------------------------------------------------------------
88
|
9-
| Outline all the validation rules here
9+
| Outline all the validation rules here for your resource
1010
|
1111
|
1212
*/
1313

14-
'rules' => [
15-
'name' => 'required|max:255',
16-
'email' => 'required|email'
17-
]
18-
14+
'rules' => [
15+
'name' => 'required|min:3',
16+
]
1917
];
File renamed without changes.
File renamed without changes.

src/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
Route::post('validate', 'RichardKeep\Validate\ValidationController@validate');
3+
Route::post('validate', 'Richardkeep\Validate\ValidationController');

0 commit comments

Comments
 (0)