From 93b6c4cc875b1fe0a51e96edb2039617bd731a62 Mon Sep 17 00:00:00 2001 From: Shahrokh Niakan Date: Tue, 18 Apr 2017 10:46:00 +0430 Subject: [PATCH 1/4] Pulish lang file of package by use command ( vendor:publish ) lang file will be added to config files of project --- src/PersianValidationServiceProvider.php | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/PersianValidationServiceProvider.php b/src/PersianValidationServiceProvider.php index 9167a5a..b23afb7 100644 --- a/src/PersianValidationServiceProvider.php +++ b/src/PersianValidationServiceProvider.php @@ -4,6 +4,7 @@ use Illuminate\Support\ServiceProvider; use Validator; +use App; /** * @author Shahrokh Niakan @@ -20,103 +21,91 @@ class PersianValidationServiceProvider extends ServiceProvider */ public function boot() { + // publish lang file to config file of project + $this->publishes([ + __DIR__.'/../lang/' . App::getLocale() . '.php' => config_path( App::getLocale() . '_validation_lang.php' ), + ]); // create custom rule for Alpha Validator::extend('persian_alpha', 'ValidationRules@Alpha'); // create custom message for Alpha Validator::replacer('persian_alpha', 'ValidationMessages@AlphaMsg'); - // create custom rule for Num Validator::extend('persian_num', 'ValidationRules@Num'); // create custom message for Num Validator::replacer('persian_num', 'ValidationMessages@NumMsg'); - // create custom rule for AlphaNum Validator::extend('persian_alpha_num', 'ValidationRules@AlphaNum'); // create custom message for AlphaNum Validator::replacer('persian_alpha_num', 'ValidationMessages@AlphaNumMsg'); - // create custom rule for IranMobile Validator::extend('iran_mobile', 'ValidationRules@IranMobile'); // create custom message for IranMobile Validator::replacer('iran_mobile', 'ValidationMessages@IranMobileMsg'); - // create custom rule for Sheba Validator::extend('sheba', 'ValidationRules@Sheba'); // create custom message for Sheba Validator::replacer('sheba', 'ValidationMessages@ShebaMsg'); - // create custom rule for MelliCode Validator::extend('melli_code', 'ValidationRules@MelliCode'); // create custom message for MelliCode Validator::replacer('melli_code', 'ValidationMessages@MelliCodeMsg'); - // create custom rule for IsNotPersian Validator::extend('is_not_persian', 'ValidationRules@IsNotPersian'); // create custom message for IsNotPersian Validator::replacer('is_not_persian', 'ValidationMessages@IsNotPersianMsg'); - // create custom rule for LimitArray Validator::extend('limited_array', 'ValidationRules@LimitedArray'); // create custom message for LimitArray Validator::replacer('limited_array', 'ValidationMessages@LimitedArrayMsg'); - // create custom rule for UnSignedNum Validator::extend('unsigned_num', 'ValidationRules@UnSignedNum'); // create custom message for UnSignedNum Validator::replacer('unsigned_num', 'ValidationMessages@UnSignedNumMsg'); - // create custom rule for AlphaSpace Validator::extend('alpha_space', 'ValidationRules@AlphaSpace'); // create custom message for AlphaSpace Validator::replacer('alpha_space', 'ValidationMessages@AlphaSpaceMsg'); - // create custom rule for Url Validator::extend('a_url', 'ValidationRules@Url'); // create custom message for Url Validator::replacer('a_url', 'ValidationMessages@UrlMsg'); - // create custom rule for Domain Validator::extend('a_domain', 'ValidationRules@Domain'); // create custom message for Domain Validator::replacer('a_domain', 'ValidationMessages@DomainMsg'); - // create custom rule for More Validator::extend('more', 'ValidationRules@More'); // create custom message for More Validator::replacer('more', 'ValidationMessages@MoreMsg'); - // create custom rule for Less Validator::extend('less', 'ValidationRules@Less'); // create custom message for Less Validator::replacer('less', 'ValidationMessages@LessMsg'); - // create custom rule for IranPhone Validator::extend('iran_phone', 'ValidationRules@IranPhone'); // create custom message for IranPhone Validator::replacer('iran_phone', 'ValidationMessages@IranPhoneMsg'); - // create custom rule for CardNumber Validator::extend('card_number', 'ValidationRules@CardNumber'); // create custom message for CardNumber Validator::replacer('card_number', 'ValidationMessages@CardNumberMsg'); - // create custom rule for Address Validator::extend('address', 'ValidationRules@Address'); // create custom message for Address @@ -137,10 +126,8 @@ public function boot() */ public function register() { - $this->app->bind('ValidationRules', 'Anetwork\Validation\ValidationRules'); $this->app->bind('ValidationMessages', 'Anetwork\Validation\ValidationMessages'); - } } From 9f800631467a43bed80c4870e614762d41611827 Mon Sep 17 00:00:00 2001 From: Shahrokh Niakan Date: Tue, 18 Apr 2017 12:41:51 +0430 Subject: [PATCH 2/4] Pulish lang file of package and updated readme by use command ( vendor:publish ) lang file will be added to this path resources/lang/validation --- src/PersianValidationServiceProvider.php | 5 +++-- src/ValidationMessages.php | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/PersianValidationServiceProvider.php b/src/PersianValidationServiceProvider.php index b23afb7..5857c59 100644 --- a/src/PersianValidationServiceProvider.php +++ b/src/PersianValidationServiceProvider.php @@ -21,9 +21,9 @@ class PersianValidationServiceProvider extends ServiceProvider */ public function boot() { - // publish lang file to config file of project + // publish lang file to resources/lang/validation $this->publishes([ - __DIR__.'/../lang/' . App::getLocale() . '.php' => config_path( App::getLocale() . '_validation_lang.php' ), + __DIR__.'/../lang/' . App::getLocale() . '.php' => resource_path( 'lang/validation/' . App::getLocale() . '.php' ), ]); // create custom rule for Alpha @@ -129,5 +129,6 @@ public function register() $this->app->bind('ValidationRules', 'Anetwork\Validation\ValidationRules'); $this->app->bind('ValidationMessages', 'Anetwork\Validation\ValidationMessages'); + } } diff --git a/src/ValidationMessages.php b/src/ValidationMessages.php index 84e2855..2f0061e 100644 --- a/src/ValidationMessages.php +++ b/src/ValidationMessages.php @@ -26,7 +26,11 @@ public function __construct() { $this->lang = \App::getLocale(); - $this->config = include __DIR__ . '/../lang/' . $this->lang . '.php'; + if(! file_exists(resource_path('lang/validation/' . $this->lang . '.php'))){ + $this->config = include __DIR__ . '/../lang/' . $this->lang . '.php'; + } else { + $this->config = include resource_path('lang/validation/' . $this->lang . '.php'); + } } From c710b8e21ca3bbb0d42850894e3cda22ed413afb Mon Sep 17 00:00:00 2001 From: Shahrokh Niakan Date: Tue, 18 Apr 2017 12:43:35 +0430 Subject: [PATCH 3/4] Update readme --- readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readme.md b/readme.md index 9ea5b5a..92aae82 100644 --- a/readme.md +++ b/readme.md @@ -194,3 +194,7 @@ Validator::make( $request->all(), [ ]); ``` + +### publish:vendor +You can run publish:vendor command to have custom lang file of package on this path ( resources/lang/validation ) + From 7e00c3df3162784fa3b9c162bd924f098ec3e0a1 Mon Sep 17 00:00:00 2001 From: Shahrokh Niakan Date: Tue, 18 Apr 2017 12:45:51 +0430 Subject: [PATCH 4/4] Update readme --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 92aae82..2f4a22f 100644 --- a/readme.md +++ b/readme.md @@ -195,6 +195,6 @@ Validator::make( $request->all(), [ ]); ``` -### publish:vendor -You can run publish:vendor command to have custom lang file of package on this path ( resources/lang/validation ) +### vendor:publish +You can run vendor:publish command to have custom lang file of package on this path ( resources/lang/validation )