<legend id='m0F8p'><style id='m0F8p'><dir id='m0F8p'><q id='m0F8p'></q></dir></style></legend>
<i id='m0F8p'><tr id='m0F8p'><dt id='m0F8p'><q id='m0F8p'><span id='m0F8p'><b id='m0F8p'><form id='m0F8p'><ins id='m0F8p'></ins><ul id='m0F8p'></ul><sub id='m0F8p'></sub></form><legend id='m0F8p'></legend><bdo id='m0F8p'><pre id='m0F8p'><center id='m0F8p'></center></pre></bdo></b><th id='m0F8p'></th></span></q></dt></tr></i><div id='m0F8p'><tfoot id='m0F8p'></tfoot><dl id='m0F8p'><fieldset id='m0F8p'></fieldset></dl></div>

    • <bdo id='m0F8p'></bdo><ul id='m0F8p'></ul>
    <tfoot id='m0F8p'></tfoot>

    <small id='m0F8p'></small><noframes id='m0F8p'>

    1. Laravel 4:验证前修剪输入的最佳实践

      时间:2023-10-31

      1. <i id='VJD5V'><tr id='VJD5V'><dt id='VJD5V'><q id='VJD5V'><span id='VJD5V'><b id='VJD5V'><form id='VJD5V'><ins id='VJD5V'></ins><ul id='VJD5V'></ul><sub id='VJD5V'></sub></form><legend id='VJD5V'></legend><bdo id='VJD5V'><pre id='VJD5V'><center id='VJD5V'></center></pre></bdo></b><th id='VJD5V'></th></span></q></dt></tr></i><div id='VJD5V'><tfoot id='VJD5V'></tfoot><dl id='VJD5V'><fieldset id='VJD5V'></fieldset></dl></div>

          <small id='VJD5V'></small><noframes id='VJD5V'>

          • <legend id='VJD5V'><style id='VJD5V'><dir id='VJD5V'><q id='VJD5V'></q></dir></style></legend>
          • <tfoot id='VJD5V'></tfoot>

              <bdo id='VJD5V'></bdo><ul id='VJD5V'></ul>
                <tbody id='VJD5V'></tbody>
                本文介绍了Laravel 4:验证前修剪输入的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                现在,我分别对每个输入进行修剪,如下代码:

                Now, I do trim for each input separately like below code:

                $username = trim(Input::get('username'));
                $password = trim(Input::get('password'));
                $email    = trim(Input::get('email'));
                
                $validator = Validator::make(array('username' => $username, 
                                                   'password' => $password, 
                                                   'email'    => $email), 
                                             array('username' => 'required|min:6', 
                                                   'password' => 'required|min:6', 
                                                   'email'    => 'email'));
                

                是否有任何方法可以同时进行修剪

                Is any approach to do Trim at the same time with

                Input::all()Input::only('username', 'password', 'email')?

                这样做的最佳做法是什么?

                And what is the best practice to do this?

                推荐答案

                注意: 如果您的任何输入是数组(例如data[]").

                Note: This solution won't work if any of your inputs are arrays (such as "data[]").

                你可以试试这个,在验证前使用这行代码修剪:

                You may try this, trim using this one line of code before validation:

                Input::merge(array_map('trim', Input::all()));
                

                现在完成其余的编码

                $username = Input::get('username'); // it's trimed 
                // ...
                Validator::make(...);
                

                如果你想从修剪中排除一些输入,那么你可以使用以下 if all()

                If you want to exclude some inputs from trimming then you may use following instead if all()

                Input::except('password');
                

                或者你可以使用

                Input::only(array('username'));
                

                更新:由于 Laravel 5.4.* 输入因新的 TrimStrings 中间件而被修剪.因此,无需担心,因为此中间件会在每个请求上执行,并且它还处理数组输入.

                Update: Since Laravel 5.4.* inputs are trimmed because of new TrimStringsmiddleware. So, no need to worry about it because this middleware executes on every request and it handles array inputs as well.

                这篇关于Laravel 4:验证前修剪输入的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在 Laravel 4 中自动加载 Guzzle? 下一篇:如何让 Laravel 返回视图的“Content-Type"?标头为“应用程序/javascript&quo

                相关文章

              1. <i id='tSFqJ'><tr id='tSFqJ'><dt id='tSFqJ'><q id='tSFqJ'><span id='tSFqJ'><b id='tSFqJ'><form id='tSFqJ'><ins id='tSFqJ'></ins><ul id='tSFqJ'></ul><sub id='tSFqJ'></sub></form><legend id='tSFqJ'></legend><bdo id='tSFqJ'><pre id='tSFqJ'><center id='tSFqJ'></center></pre></bdo></b><th id='tSFqJ'></th></span></q></dt></tr></i><div id='tSFqJ'><tfoot id='tSFqJ'></tfoot><dl id='tSFqJ'><fieldset id='tSFqJ'></fieldset></dl></div>

                  <tfoot id='tSFqJ'></tfoot>

                  <small id='tSFqJ'></small><noframes id='tSFqJ'>

                    <bdo id='tSFqJ'></bdo><ul id='tSFqJ'></ul>

                  1. <legend id='tSFqJ'><style id='tSFqJ'><dir id='tSFqJ'><q id='tSFqJ'></q></dir></style></legend>