duanpu2272 2015-11-21 12:07
浏览 29
已采纳

Laravel 5.1仅在生产时验证输入

so I'm adding Google's recaptcha to my Laravel project. I'm using the basic Auth that comes with Laravel 5.1. I'm using this class for the recaptcha https://github.com/greggilbert/recaptcha

In my AuthController.php I have this function which is validating my current form. I would however like to add a check for the racaptcha but only when the server is production....

/**
 * Get a validator for an incoming registration request.
 *
 * @param  array $data
 *
 * @return \Illuminate\Contracts\Validation\Validator
 */
protected function validator(array $data)
{
    return Validator::make($data, [
        'name'                 => 'required|max:255',
        'email'                => 'required|email|max:255|unique:users',
        'password'             => 'required|confirmed|min:6',
        'g-recaptcha-response' => 'required|recaptcha',
    ]);
}

The part of the validator that I only want on product is

'g-recaptcha-response' => 'required|recaptcha',

What would be the easiest way to achieve this?

  • 写回答

1条回答 默认 最新

  • dongpian4954 2015-11-21 12:27
    关注

    After checking the elixir.config object, it seems that the --production flag sets the elixir.config.production variable to true.

    So it's possible to wrap the execution of a specific task in an if(elixir.config.production) statement, allowing you to trigger them when the environment is "production", or if you manually specified it by using the --production flag from the command line.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料