Download the PHP package kalfheim/sanitizer without Composer
On this page you can find all versions of the php package kalfheim/sanitizer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kalfheim/sanitizer
More information about kalfheim/sanitizer
Files in kalfheim/sanitizer
Package sanitizer
Short Description Data sanitizer for PHP with built-in Laravel support.
License MIT
Homepage http://github.com/kalfheim/sanitizer
Informations about the package sanitizer
sanitizer
Data sanitizer for PHP with built-in Laravel support.
Installation
composer require kalfheim/sanitizer
Usage
Examples
Registrars
A registrar allows you to bind custom sanitizer functions to the sanitizer.
Laravel Support
Register the service provider in your config/app.php
as per usual...
Alfheim\Sanitizer\SanitizerServiceProvider::class,
Extending the FormRequest
This is where the package shines.
By extending the Alfheim\Sanitizer\Laravel\FormRequest
on your base App\Http\Requests\Request
class (instead of the default Illuminate\Foundation\Http\FormRequest
), you'll be able to define sanitation rules in a sanitize
method on the given form request, similar to how you define validation rules in the rules
method.
Let me show you in code...
That's it! Now it's trivial to define sanitation rules on your form requests...
For completeness, I'll show you the controller...
Helper Trait
Alfheim\Sanitizer\Laravel\SanitizesRequests
This trait adds a sanitize
method on the class.
May be useful if you want to sanitize user input in a controller without setting up a custom request class (however, it can be used from anywhere.)
Example usage...
Registering custom sanitizer functions with Laravel
The service provider will register a shared Alfheim\Sanitizer\Registrar\RegsitrarInterface
instance with the IoC container, which will then be set on subsequent Alfheim\Sanitizer\Sanitizer
instances. This means you can easily register custom sanitizer functions...
License
Kristoffer Alfheim