Laravel:请求规则不正确时登录数据库

Laravel: log in the database if the rule of a request ist not correct

如果请求的规则不正确,我想登录数据库。

\Validator::extend( 'my_validator', function ( $attribute, $value, $parameters ) {
$result = \DB::table( 'table' )->where( 'field1', $value )->where( 'field2', 'Y' )->exists();
if ( !$result ) {
    // Log in database the value of request->field3, request->field4, ...
    $log = new Log();
    $log->date = Carbon::now();
    $log->field3 = $request->field3;  // <<= How can I access here the input request of the fromula?
    $log->field4 = $request->field4;  // <<= How can I access here the input request of the fromula?
    // ... 
    $status = $log->save();
}
return $result;
} );

$validationRules = [
   'field' => 'my_validator'
];

要访问请求字段,您应该使用外观 \Request\Input。在这种情况下,您可以使用代码 \Request::get('field1');

轻松获取任何字段的值