add validation message with replacer

This commit is contained in:
Arandi Lopez 2016-07-18 22:47:57 -05:00
parent a80a93c94c
commit a8a3774305
3 changed files with 20 additions and 1 deletions

View File

@ -3,16 +3,25 @@
namespace LaravelProfane;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Lang;
class ProfaneServiceProvider extends ServiceProvider
{
public function register()
{
# code...
$this->loadTranslationsFrom(__DIR__.'/lang', 'laravel-profane');
$this->publishes([
__DIR__.'/lang' => resource_path('lang/vendor/laravel-profane'),
]);
}
public function boot()
{
Validator::extend('profane', 'LaravelProfane\ProfaneValidator@validate');
Validator::replacer('profane', function($message, $attribute, $rule, $parameters) {
return str_replace(':attribute', $attribute, $message);
});
}
}

View File

@ -0,0 +1,5 @@
<?php
return [
'profane' => 'The :attribute contains vulgar content'
];

View File

@ -0,0 +1,5 @@
<?php
return [
'profane' => 'El :attribute contiene palabras vulgares.'
];