for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Vicens\Captcha\Middleware;
use Closure;
use Illuminate\Contracts\Validation\Factory;
class CaptchaMiddleware
{
/**
* @var Factory
*/
protected $validator;
* CaptchaMiddleware constructor.
*
* @param Factory $validator
public function __construct(Factory $validator)
$this->validator = $validator;
}
* @param $request
* @param Closure $next
* @param string $captchaKey
* @return mixed
public function handle($request, Closure $next, $captchaKey = 'captcha')
$this->validate($request, $captchaKey);
return $next($request);
* 验证
* @param $captchaKey
protected function validate($request, $captchaKey)
$this->validator->make(
$request->only($captchaKey),
$this->rules($captchaKey),
$this->message($captchaKey)
)->validate();
* 验证规则
* @return array
array<string,string>
This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.
array
protected function rules($captchaKey)
return [
$captchaKey => 'required|captcha'
];
* 验证的错误消息
protected function message($captchaKey)
$captchaKey
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.
return [];
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.