repat/laravel-validator-emojis

Laravel Validator for Emojis

0.3 2024-04-02 10:13 UTC

This package is auto-updated.

Last update: 2024-12-02 11:34:31 UTC


README

Latest Version on Packagist Total Downloads

laravel-validator-emojis is a custom Rule Object / Validator for Laravel that validates emojis using steppinghat/emoji-detector

Installation

$ composer require repat/laravel-validator-emojis

Documentation

use Illuminate\Http\Request;
use Repat\LaravelRules\ContainsEmojis;
use Repat\LaravelRules\DoesntContainEmojis;

// ...

public function controllerMethod(Request $request) {
    // Contains ANY emoji
    $request->validate([
        'string_to_validate' => new ContainsEmojis(),
    ]);

    // Contains ANY of given emoji
    $request->validate([
        'string_to_validate' => new ContainsEmojis(["🪂", "🤿"]), // $all = false
    ]);

    // Contains ALL given emoji
    $request->validate([
        'string_to_validate' => new ContainsEmojis(emojis: ["🔑", "🟤"], all: true),
    ]);

    // Contains NO emojis at all
    $request->validate([
        'string_to_validate' => new DoesntContainEmojis(),
    ]);
}

Tests

vendor/bin/phpunit

License

Version

  • Version 0.3

Contact

repat

Flattr this git repo