From 8b5b896bfebfb39173a2ef9767711534f370212d Mon Sep 17 00:00:00 2001 From: Eduardo Aguad Date: Wed, 11 Oct 2017 16:57:42 -0300 Subject: [PATCH] Add validator custom message --- composer.json | 14 ++-- src/Laravel/ChileanBundleServiceProvider.php | 70 ++++++++++---------- 2 files changed, 44 insertions(+), 40 deletions(-) diff --git a/composer.json b/composer.json index ff872b1..e44cc2c 100644 --- a/composer.json +++ b/composer.json @@ -32,12 +32,14 @@ "Freshwork\\ChileanBundle\\": "src/" } }, - "laravel": { - "providers": [ - "Freshwork\\ChileanBundle\\Laravel\\ChileanBundleServiceProvider" - ], - "aliases": { - "Rut": "Freshwork\\ChileanBundle\\Facades\\Rut" + "extra": { + "laravel": { + "providers": [ + "Freshwork\\ChileanBundle\\Laravel\\ChileanBundleServiceProvider" + ], + "aliases": { + "Rut": "Freshwork\\ChileanBundle\\Facades\\Rut" + } } } } diff --git a/src/Laravel/ChileanBundleServiceProvider.php b/src/Laravel/ChileanBundleServiceProvider.php index a0994f8..ffbe43d 100644 --- a/src/Laravel/ChileanBundleServiceProvider.php +++ b/src/Laravel/ChileanBundleServiceProvider.php @@ -5,47 +5,49 @@ use Illuminate\Support\ServiceProvider; use Validator; -class ChileanBundleServiceProvider extends ServiceProvider { - - /** - * Indicates if loading of the provider is deferred. - * - * @var bool - */ - protected $defer = false; - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - - } - - public function boot(){ - Validator::extend('cl_rut', function($attribute, $value, $parameters) - { +class ChileanBundleServiceProvider extends ServiceProvider +{ + + /** + * Indicates if loading of the provider is deferred. + * + * @var bool + */ + protected $defer = false; + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + + } + + public function boot() + { + Validator::extend('cl_rut', function ($attribute, $value, $parameters) { return Rut::parse($value)->quiet()->validate(); }); + Validator::replacer('cl_rut', function ($message, $attribute, $rule, $parameters) { + return str_replace('El atributo :attribute es inválido', $parameters[0], $message); + }); - app()->bind('rut', function() - { + app()->bind('rut', function () { return new Rut; }); - } - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return array(); - } + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return array(); + } }