Looking to hire Laravel developers? Try LaraJobs

laravel-unicode-normalizer maintained by junholee14

Description
A set of features to make working with unicode normalization in Laravel
Author
Last update
2024/03/04 10:19 (dev-main)
License
Links
Downloads
1 314

Comments
comments powered by Disqus

Laravel Unicode Normalizer Package

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