PHP code example of peeyush-budhia / sanitizer

1. Go to this page and download the library: Download peeyush-budhia/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/ */

    

peeyush-budhia / sanitizer example snippets


[
    'name' => 'Peeyush',
    'birth_date' => 'September 10, 1987',
    'email' => '[email protected]',
    'phone' => '0000000000'
    'json' => ['name' => 'Peeyush'],
];

'providers' => [
        /*
         * Package Service Providers...
         */
        \Peeyush\Sanitizer\SanitizerServiceProvider::class,
    ]

'aliases' => [
        /*
         * Package aliases...
         */
        'Sanitizer' => \Peeyush\Sanitizer\Facade\SanitizerFacade::class,
    ],

$data = Sanitizer::make($data, $filters)->sanitize();

namespace App\Http\Requests;

use Peeyush\Sanitizer\SanitizeInput;

class ExampleRequest extends Request
{
    use SanitizeInput;
    
    public function filters()
    {
        return [
            'name' => 'trim|capitalize',
        ];
    }
}

class RemoveStringFilter implements \Peeyush\Sanitizer\Contracts\Filter
{
    public function apply($value, array $options)
    {
        return str_replace($options, '', $value);
    }
}

$filters = [
    'remove_strings' => RemoveStringsFilter::class,
];

$sanitize = new Sanitizer($data, $filters)
 php
use Peeyush\Sanitizer\Sanitizer;

$data = [
    'name' => ' peeyush ',
    'birth_date' => '1987-09-10',
    'email' => '[email protected]',
    'phone' => '(000)-000-00-00',
    'json' => '{"name":"Peeyush"}',
];

$filters = [
    'name' => 'trim|capitalize',
    'birth_date' => 'trim|format_date:"Y-m-d","F j, Y"',
    'email' => ['trim', 'lowercase'],
    'phone' => 'digit'
    'json' => 'cast:array',
];

$sanitizer = new Sanitizer($data, $filters);

var_dump($sanitizer);
sh
php artisan vendor:publish --provider="Peeyush\Sanitizer\SanitizerServiceProvider"
sh
php artisan make:Request ExampleRequest