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.

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

报告相同问题?