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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测