Skip to content

Commit

Permalink
laravel support
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-tebiev committed May 28, 2024
1 parent a318c5d commit 4f35f78
Showing 1 changed file with 62 additions and 3 deletions.
65 changes: 62 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
[![Packagist Downloads](https://img.shields.io/packagist/dt/beeyev/disposable-email-filter-php)](https://packagist.org/packages/beeyev/disposable-email-filter-php)
[![Supported PHP Versions](https://img.shields.io/packagist/dependency-v/beeyev/disposable-email-filter-php/php.svg)](https://packagist.org/packages/beeyev/disposable-email-filter-php)


PHP package that detects disposable (temporary/throwaway/fake) email addresses.
PHP package that detects disposable (temporary/throwaway/fake) email addresses. It is framework-agnostic and has no dependencies, but includes support for Laravel.
It validates email addresses to ensure they are genuine,
which is useful for managing account sign-ups and assessing the number of legitimate email addresses in your system.
This tool also helps to avoid communication errors and blocks spam addresses.
Expand All @@ -17,6 +16,8 @@ Supported PHP versions: `v7.2 - v8.3`

## Installation and Usage examples

> Read below for Laravel specific instructions.
Require this package with composer using the following command:

```bash
Expand Down Expand Up @@ -108,14 +109,72 @@ if ($disposableEmailFilter->isEmailAddressValid($emailAddress)) {
$disposableEmailFilter->isDisposableEmailAddress($emailAddress);
}
```

## Laravel specific usage

This package includes a service provider and form validation rule for Laravel.

### Install the package (Laravel)

```bash
composer require beeyev/disposable-email-filter-php
```

The package will be automatically registered using Laravel auto-discovery mechanism.
But if you need to do it manually, you can add the following line to the `providers` array in the `config/app.php` file:

```php
Beeyev\DisposableEmailFilter\Adapters\Laravel\DisposableEmailFilterServiceProvider::class,
```

### Form validation (Laravel)

Use validation rule `disposable_email` or object `new DisposableEmailRule()`,
to check that specific field does not contain a disposable email address.

> ❗ Place it after the email validator to ensure that only valid emails are processed.
Example:

```php
// Using validation rule name:
'email_field' => 'required|email|disposable_email',

// Or using a validation rule object:
'email_field' => ['email', new DisposableEmailRule()],
```

### Using facades (Laravel)

You can use the `DisposableEmail` facade to access the `DisposableEmailFilter` instance:

```php
use Beeyev\DisposableEmailFilter\Adapters\Laravel\Facades\DisposableEmail;

DisposableEmail::isEmailAddressValid('[email protected]');
```

### Config file and translations (Laravel)

Optionally, you can publish the config file and translations to customize the package behavior:

```bash
php artisan vendor:publish --tag=disposable-email-filter
```

This command will create a `disposable-email-filter.php` config file in the `config` directory
and translation files in the `lang/vendor/disposable-email-filter` directory.

## Updating

Since the list of disposable email domains is regularly updated, it is important to keep the package up to date.
A new `PATCH` version of the package is [released](https://github.com/beeyev/disposable-email-filter-php/releases/) whenever the list is updated.
These updates are safe and non-breaking, allowing you to update the package via this composer command:
These updates are safe and non-breaking, allowing you to update the package via this composer command:

```bash
composer update beeyev/disposable-email-filter-php
```

> You can run this command every time in CI/CD pipelines before the project is deployed.
## Contribution
Expand Down

0 comments on commit 4f35f78

Please sign in to comment.