Waavi / Sanitizer

Data sanitizer and form request input sanitation for Laravel 5.
MIT License
428 stars 87 forks source link

Question: It is possible to use custom filters when using SanitizesInput on my FormRequest? #24

Open MatiasManevi opened 5 years ago

MatiasManevi commented 5 years ago

Hello. it is possible to do this?

This is my Request class:

`namespace App\Http\Requests\API;

use App\Models\Concept; use InfyOm\Generator\Request\APIRequest; use Waavi\Sanitizer\Laravel\SanitizesInput;

class CreateConceptAPIRequest extends APIRequest { use SanitizesInput;

public function filters() {
    return [
        'name'  => 'trim|strip_tags|escape|lowercase',
    ];
}
/**
 * Determine if the user is authorized to make this request.
 *
 * @return bool
 */
public function authorize()
{
    return true;
}
/**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules()
{
    return Concept::$rules;
}

}`

MatiasManevi commented 5 years ago

I have just test one thing and it work like a charm.. It appears to be possible, this is an updated code of my use of filters on FormRequest class

public function filters() { return [ 'name' => 'trim|strip_tags|escape|lowercase|hash', ]; }

public function customFilters() { return [ 'hash' => function($value, $options = []) { return sha1($value); }, ]; }

For testing purposes Ive implemented a hashing fitler function and this is the result:

{ "success": true, "data": { "name": "c205c127a6626be13e2e0d1c95adc9a7c0b6d6b2", "type": true, "perceive_vat_tax": false, "perceive_admin_profit": false, "perceive_interest": false, "account_id": 11, "user_id": 5, "updated_at": "2018-11-23 16:13:58", "created_at": "2018-11-23 16:13:58", "id": 399 }, "message": "Concept saved successfully" }

I hope it helps someone else;.