Skip to content

Commit

Permalink
Merge pull request #6 from eaguad1337/laravel/custom-message
Browse files Browse the repository at this point in the history
Add validator custom message and fix composer auto discovery
  • Loading branch information
gdespirito authored Oct 11, 2017
2 parents 468468d + 8b5b896 commit 1f18a78
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 40 deletions.
14 changes: 8 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
70 changes: 36 additions & 34 deletions src/Laravel/ChileanBundleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}

0 comments on commit 1f18a78

Please sign in to comment.