junholee14 / laravel-unicode-normalizer
A set of features to make working with unicode normalization in Laravel
Requires
- php: ^8.1
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- laravel/pint: ^1.14
- orchestra/testbench: ^6.23|^7.0|^8.0|^9.0
- pestphp/pest: ^1.23|^2.6
- phpstan/phpstan: ^1.10
README
Introduction
The Laravel Unicode Normalizer package provides a simple and efficient way to normalize Unicode characters in your Laravel application. This package includes middleware for easy normalization of incoming requests and a validation rule to ensure that data is normalized before processing.
Requirements
- PHP >= 8.1
- Laravel >= 10
intl
PHP extension
Installation
To install the package, run the following command in your Laravel project:
composer require junholee14/laravel-unicode-normalizer
After installation, you can publish the package configuration using:
php artisan vendor:publish --provider="Junholee14\LaravelUnicodeNormalizer\UnicodeNormalizationProvider"
The default normalization form is NFC
. You can change this in the published configuration file.
Usage
Middleware
The NormalizeUnicode
middleware automatically normalizes all incoming request data to the specified Unicode form. To use it, simply add the middleware to your route or middleware group in app/Http/Kernel.php
:
// app/Http/Kernel.php protected $middlewareAliases = [ ... 'normalizeUnicode' => \Junholee14\LaravelUnicodeNormalizer\Middlewares\NormalizeUnicode::class, ];
Validation Rule
The package also provides a normalize_unicode
validation rule to ensure that data is in normalized form. You can use this rule like any other Laravel validation rule:
$request->validate([ 'input_field' => ['required', 'string', new NormalizedUnicode()], ]);