PHP code example of repat / laravel-validator-emojis

1. Go to this page and download the library: Download repat/laravel-validator-emojis library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

repat / laravel-validator-emojis example snippets



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(),
    ]);
}