1. Go to this page and download the library: Download kalfheim/sanitizer 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/ */
kalfheim / sanitizer example snippets
php
use Alfheim\Sanitizer\Sanitizer;
use Alfheim\Sanitizer\Registrar\BaseRegistrar;
// Create a new registrar instance...
$registrar = new BaseRegistrar;
// Add custom sanitation rules to the registrar...
$registrar->register('palindromify', function (string $value) {
return sprintf('%s%s', $value, strrev($value));
});
// Create a new sanitizer and bind the registrar...
$sanitizer = Sanitizer::make([
'number' => 'palindromify',
])->setRegistrar($registrar);
$input = $sanitizer->sanitize([
'number' => '123',
]);
var_dump($input); // ['number' => '123321']
php
// app/Http/Requests/Request.php
namespace App\Http\Requests;
use Alfheim\Sanitizer\Laravel\FormRequest;
// Instead of `Illuminate\Foundation\Http\FormRequest`
abstract class Request extends FormRequest
{
//
}
php
// app/Http/Requests/FooRequest.php
namespace App\Http\Requests;
class FooRequest extends Request
{
// Sanitation rules...
public function sanitize()
{
return [
'name' => 'trim|ucwords',
'email' => 'trim|mb_strtolower',
];
}
// And of course, validation is defined as per usual...
public function rules()
{
return [
'name' => '
php
public function sanitize(Illuminate\Http\Request $request, array $ruleset): array
php
namespace App\Http\Controllers\FooController;
use Illuminate\Http\Request;
use Alfheim\Sanitizer\Laravel\SanitizesRequests;
class FooController extends Controller
{
use SanitizesRequests;
public function store(Request $request)
{
$input = $this->sanitize($request, [
'name' => 'trim|ucwords',
'email' => 'trim|mb_strtolower',
]);
// $input now contains the sanitized request input.
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.