Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit 2c64b5e

Browse files
committed
Finishing the remote validation docs and procedures for route caching
1 parent c3cd371 commit 2c64b5e

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ After publishing configuration file, you can find it in config/laravalid folder.
7171
| plugin | Choose plugin you want to use | See [Plugins and Supported Rules](#plugins-and-supported-rules) |
7272
| useLaravelMessages | If it is true, laravel validation messages are used in client side otherwise messages of chosen plugin are used | `boolean`. See [Validation Messages](#validation-messages) |
7373
| route | Route name for remote validation | Any route name (default: laravalid). The route will receive an argument named `rule` |
74-
| action | A custom action to run the remote validation procedure | An action string, such as `\\App\\Http\\Controllers\\SiteController@getValidation` (unfortunately you need to use the complete namespace here). You must create that action if you plan to run remote validations. This is needed if you want to cache routes (`./artisan route:cache`)
74+
| action | A custom action to run the remote validation procedure | An action string, such as `SiteController@getValidation` (watch out for route conflicts, this will be added after your `routes.php` file is processed). This is needed if you want to cache routes (`./artisan route:cache`). If you include this, for the default behaviour you can return from your method `app('laravalid')->remoteValidation($rule)`. |
7575

7676
#### Validation Messages
7777
If you set `useLaravelMessages` to `true`, you're able to use (Laravel's Localization package)[l10n] to generate validation messages. To do so, follow the [docs][l10n] to get the package configured (by setting your default/fallback/current locales). Then, create a folder for each locale (as the docs says) and create a `validation.php` file for each one. Inside those files you'll set a message for each rule name, as follows:

src/Laravalid/FormBuilder.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ public function resetValidation()
6464
$this->converter()->reset();
6565
}
6666

67+
/**
68+
* Executes the remote validation and returns true or the error message
69+
* @param string $rule
70+
* @return array|\Illuminate\Http\JsonResponse|mixed
71+
*/
72+
public function remoteValidation($rule)
73+
{
74+
return $this->converter->route()->convert($rule, \Input::all());
75+
}
76+
6777
/**
6878
* Opens form with a set of validation rules
6979
* @param array $rules Laravel validation rules

src/Laravalid/LaravalidServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function boot()
2929
// remote validations
3030
$routeName = \Config::get('laravalid.route');
3131
$routeAction = \Config::get('laravalid.action', function($rule) {
32-
return $this->app['laravalid']->converter()->route()->convert($rule, \Input::all());
32+
$this->app['laravalid']->remoteValidation($rule);
3333
});
3434

3535
\Route::any($routeName.'/{rule}', $routeAction);

0 commit comments

Comments
 (0)