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

Commit

Permalink
Finishing the remote validation docs and procedures for route caching
Browse files Browse the repository at this point in the history
  • Loading branch information
igorsantos07 committed Nov 15, 2015
1 parent c3cd371 commit 2c64b5e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ After publishing configuration file, you can find it in config/laravalid folder.
| plugin | Choose plugin you want to use | See [Plugins and Supported Rules](#plugins-and-supported-rules) |
| 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) |
| route | Route name for remote validation | Any route name (default: laravalid). The route will receive an argument named `rule` |
| 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`)
| 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)`. |

#### Validation Messages
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:
Expand Down
10 changes: 10 additions & 0 deletions src/Laravalid/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public function resetValidation()
$this->converter()->reset();
}

/**
* Executes the remote validation and returns true or the error message
* @param string $rule
* @return array|\Illuminate\Http\JsonResponse|mixed
*/
public function remoteValidation($rule)
{
return $this->converter->route()->convert($rule, \Input::all());
}

/**
* Opens form with a set of validation rules
* @param array $rules Laravel validation rules
Expand Down
2 changes: 1 addition & 1 deletion src/Laravalid/LaravalidServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function boot()
// remote validations
$routeName = \Config::get('laravalid.route');
$routeAction = \Config::get('laravalid.action', function($rule) {
return $this->app['laravalid']->converter()->route()->convert($rule, \Input::all());
$this->app['laravalid']->remoteValidation($rule);
});

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

0 comments on commit 2c64b5e

Please sign in to comment.