think.studio/laravel-blocklist-check

Simple blocklist validator for laravel.

2.1.0 2023-08-19 17:58 UTC

This package is auto-updated.

Last update: 2024-10-19 20:26:44 UTC


README

Packagist License Packagist Version Total Downloads Build Status Code Coverage Scrutinizer Code Quality

Add model to blocklist/allowlist,

Installation

Install the package via composer:

composer require think.studio/laravel-blocklist-check

Optionally you can publish the config file with:

php artisan vendor:publish --provider="LaraBlockList\ServiceProvider" --tag="config"

Usage

Update your model:

use LaraBlockList\Contracts\CanBeInBlocklist;
use LaraBlockList\Models\HasBlocklist;

class User /* ... */ implements CanBeInBlocklist
{
    use HasBlocklist;

    /**
     * @inheritDoc
     */
    public function getBlocklistProcessor(array $args = []): BlocklistProcessor
    {
        return new BlocklistProcessor([
            new RegexChecker([ '/\.ru$/', ], [ 'email' ]),
            new RegexChecker([ /* contain cyrillic */ '/[А-Яа-яЁё]+/u', ], [ 'name', ]),
        ]);
    }

    // ...
}

Now you can run checks:

php artisan blocklist:check "\App\Models\User"
# or
php artisan blocklist:check "\App\Models\User" 123
# or
php artisan blocklist:check "\App\Models\User" --from=2020-01-01 --queue=default

Credits

  • Think Studio