aporat/laravel-filter-var

Laravel package for filtering and sanitizing request variables

v1.0.0 2020-08-19 16:52 UTC

This package is auto-updated.

Last update: 2024-04-05 23:54:55 UTC


README

Latest Stable Version Composer Downloads Build Status Code Coverage Scrutinizer Code Quality

Laravel package for filtering and sanitizing request variables

Installation

The filter-var service provider can be installed via Composer.

composer require aporat/laravel-filter-var

To use the FilterVar service provider, you must register the provider when bootstrapping your application.

Laravel

Laravel 5.5 and above

The package will automatically register provider and facade.

Laravel 5.4 and below

Add Aporat\FilterVar\Laravell\FilterVarServiceProvider to the providers section of your config/app.php:

    'providers' => [
        // ...
        Aporat\FilterVar\Laravel\FilterVarServiceProvider::class,
    ];

Add FilterVar facade to the aliases section of your config/app.php:

    'aliases' => [
        // ...
        'FilterVar' => Aporat\FilterVar\Laravel\Facade\FilterVar::class,
    ];

Or use the facade class directly:

  use Aporat\FilterVar\Laravel\Facade\FilterVar;

Now run php artisan vendor:publish to publish config/filter-var.php file in your config directory.

Lumen

Register the Aporat\FilterVar\Laravel\FilterVarServiceProvider in your bootstrap/app.php:

    $app->register(Aporat\FilterVar\Laravel\FilterVarServiceProvider::class);

Copy the filter-var.php config file in to your project:

    mkdir config
    cp vendor/aporat/laravel-filter-var/Config/filter-var.php config/filter-var.php

Configuration

In the config file you can set custom filters

Usage

Filter and escape user agent header:

$user_agent = FilterVar::filterValue('cast:string|trim|strip_tags|escape', $request->header('User-Agent'));

Credits

License

The MIT License (MIT). Please see License File for more information.