Php 验证前的Laravel验证修改请求。如果失败,返回原始文件

Php 验证前的Laravel验证修改请求。如果失败,返回原始文件,php,laravel,validation,Php,Laravel,Validation,我有一个所见即所得编辑器。当用户在编辑器中不断按空格键时,输入将如下所示 "<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>" 这很有效 但是,这里的问题是,如果其他验证规则失败,则该方法将修改oldhelper函数的返回值

我有一个所见即所得编辑器。当用户在编辑器中不断按空格键时,输入将如下所示

"<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>"
这很有效

但是,这里的问题是,如果其他验证规则失败,则该方法将修改
old
helper函数的返回值

如果原始输入是这样的

"""
<p>&nbsp;<iframe src="//www.youtube.com/embed/Mb5xcH9PcI0" width="560" height="314" allowfullscreen="allowfullscreen"></iframe></p>\r\n
<p>This is the body.</p>
"""

创建一个自定义验证器,该验证器剥离标记、计数字符,但不修改内容本身

Validator::extend('strip_min', function ($attribute, $value, $parameters, $validator) {

    $validator->addReplacer('strip_min', function($message, $attribute, $rule, $parameters){
        return str_replace([':min'], $parameters, $message);
    });

    return strlen(
        strip_tags(
            preg_replace(
                '/\s+/', 
                '', 
                str_replace('&nbsp;',"", $value)
            )
        )
    ) >= $parameters[0];
});
validation.php
lang文件中添加:

'strip_min' => 'The :attribute must be at least :strip_min characters.'   

也许您可以在修改之前备份原始值<代码>$input['original_body']=$input['body']然后尝试退回到您视图中的
原始\u body
?我知道我的想法很有味道,我只是想在这里激发一些想法。使用
session()
来做吗?这可能是一种选择。让我看看有没有其他解决办法。谢谢你的评论。如果有什么聪明的事,请打电话给我。
Validator::extend('strip_min', function ($attribute, $value, $parameters, $validator) {

    $validator->addReplacer('strip_min', function($message, $attribute, $rule, $parameters){
        return str_replace([':min'], $parameters, $message);
    });

    return strlen(
        strip_tags(
            preg_replace(
                '/\s+/', 
                '', 
                str_replace('&nbsp;',"", $value)
            )
        )
    ) >= $parameters[0];
});
'strip_min' => 'The :attribute must be at least :strip_min characters.'