Skip to content

Commit

Permalink
Merge pull request #1 from OwenMelbz/master
Browse files Browse the repository at this point in the history
Fixes the package when using config:cache
  • Loading branch information
stuyam authored Jun 2, 2017
2 parents 7b7679d + 4732b9c commit bd744ec
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Lavarel Kickbox Validator
# Lavarel Kickbox Validator
[![Packagist](https://img.shields.io/packagist/v/stuyam/laravel-kickbox-validator.svg)](https://packagist.org/packages/stuyam/laravel-kickbox-validator)
[![Packagist](https://img.shields.io/packagist/dt/stuyam/laravel-kickbox-validator.svg)](https://packagist.org/packages/stuyam/laravel-kickbox-validator)

Expand All @@ -7,29 +7,31 @@ This custom validator for Laravel uses the [kickbox.io](https://kickbox.io/) API

Also see: [Laravel Twilio Validator](https://github.com/stuyam/laravel-twilio-validator) for phone number validation.

###Step 1
## Step 1
Install via composer:

```
composer require stuyam/laravel-kickbox-validator
```

###Step 2
## Step 2
Add to your ```config/app.php``` service provider list:

```php
StuYam\KickboxValidator\KickboxValidatorServiceProvider::class
```

###Step 3
## Step 3
Add Kickbox credentials to your .env file:

```
KICKBOX_API_KEY=xxxxxxxxxx
```

## Step 4 (optional)
Publish the kickbox config with `php artisan vendor:publish --tag=kickbox`

###Usage
## Usage
Add the string 'kickbox' to a form request rules or validator like so:

```php
Expand Down
17 changes: 14 additions & 3 deletions src/KickboxValidatorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class KickboxValidatorServiceProvider extends ServiceProvider
*/
public function boot()
{
// allow publishing off the config
$this->publishes([
__DIR__.'/config/kickbox.php' => config_path('kickbox.php'),
], 'kickbox');

// load translation files
$this->loadTranslationsFrom(__DIR__ . '/lang', 'kickbox');

Expand All @@ -25,14 +30,18 @@ public function boot()

// setup custom kickbox validator
$validator->extend('kickbox', function($attribute, $value, $parameters, $validator){

// fetch the api key from the config - which allows the config to be cached
$kickboxApiKey = config('kickbox.api_key');

// throw exception if the kickbox credentials are missing from the env
if( env('KICKBOX_API_KEY') == null ) {
if( $kickboxApiKey == null ) {
// throw the custom exception defined below
throw new KickboxCredentialsNotFoundException('Please provide a KICKBOX_API_KEY in your .env file.');
}

// get kickbox key from users env file
$client = new Kickbox(env('KICKBOX_API_KEY', 'key'));
$client = new Kickbox($kickboxApiKey);
return $client->kickbox()->verify($value)->body['result'] !== 'undeliverable';
}, $translator->get('kickbox::validation.kickbox'));

Expand All @@ -46,6 +55,8 @@ public function boot()
*/
public function register()
{
//
$this->mergeConfigFrom(
__DIR__ . '/config/kickbox.php', 'kickbox'
);
}
}
5 changes: 5 additions & 0 deletions src/config/kickbox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'api_key' => env('KICKBOX_API_KEY')
];

0 comments on commit bd744ec

Please sign in to comment.