如何在$ request对象上使用Laravel 5 HTML Purifier?

时间:2016-08-15 18:10:27

标签: php laravel laravel-5 htmlpurifier

我正在使用HTMLPurifier for Laravel 5包来清理我的输入字段。目前我的store()方法是这样的:

public function store(Request $request)
{
    // Some business logic goes here

    $post = Post::create($request->all());

    // More business logic
}

和我的$request变量包含以下内容:

{
  "_token": "zbyUnJuAbSliem40B6xjWJfGOayoFlRSVIvrDlDM",
  "title": "Test Title",
  "slug": "test-title",
  "category_id": "1",
  "tags": [
    "2"
  ],
  "body": "<p>Test body.</p>"
}

如何仅在Purifier::clean()变量上使用$request方法来纯化$request->body元素?

如果我使用Purifier::clean($request->all()),则会将<p>标记添加到$request对象的所有元素,而不是body这样的元素:

{
  "_token": "<p>zbyUnJuAbSliem40B6xjWJfGOayoFlRSVIvrDlDM</p>",
  "title": "<p>Test Title</p>",
  "slug": "<p>test-title</p>",
  "category_id": "<p>1</p>",
  "tags": [
    "<p>2</p>"
  ],
  "body": "<p>Test body.</p>"
}

1 个答案:

答案 0 :(得分:0)

你能试试这个:

        Nullable<double> someVar = new Nullable<double>();
        someVar.Value = null;