groundsix/laravel-neverbounce

Laravel style wrapper for https://github.com/NeverBounce/NeverBounceAPI-PHP

1.0.1 2017-10-16 15:33 UTC

This package is auto-updated.

Last update: 2024-12-21 20:41:35 UTC


README

Latest Version on Packagist

This package allows email to be easily checked against https://neverbounce.com/.

Once installed you can do stuff like this:

$this->validate($request, [
  'email' => 'neverbounce',
]);

or

NeverBounce::valid($email);

Install

You can install the package via composer:

$ composer require ground/laravel-neverbounce

This service provider must be installed.

// config/app.php
'providers' => [
    ...
    Groundsix\Neverbounce\NeverBounceServiceProvider::class,
];

'aliases' => [
    ...
    'NeverBounce' => Groundsix\Neverbounce\Facades\NeverBounce::class,
];

You can publish the config-file with:

php artisan vendor:publish --provider="Groundsix\Neverbounce\NeverBounceServiceProvider" --tag="config"

And your Neverbounce api details should be added to .env:

NEVERBOUNCE_USERNAME=<username>
NEVERBOUNCE_SECRET_KEY=<secret key>

Usage

This package registers the Neverbounce\API\NB_Single into the application. But for conveniance provides a facade and a validator to simplify checking an email address.

Validator

class AuthController extends Controller
{
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'email' => 'required|email|max:255|unique:users|neverbounce',
            'password' => 'required|min:6|confirmed',
        ]);
    }
}

Facade

...
use NeverBounce;

class AuthController extends Controller
{
    protected function storeEmail(Request $request)
    {
        if(NeverBounce::valid($request->get('email'))){
          //do something
        }
    }
}

NB_Single

Or you can access NB_Single directly. See https://github.com/NeverBounce/NeverBounceAPI-PHP#single for more details.

...
use NeverBounce\API\NB_Single;

class AuthController extends Controller
{
    protected function storeEmail(Request $request)
    {
        if(app(NB_Single::class)->valid($request->get('email'))->is(NB_Single::GOOD)){
          //do something
        }
    }
}