2016-09-04 5 views
1

リクエストのルールが正しくない場合は、データベースにログインします。Laravel:リクエストのルールが正しくない場合は、データベースにログインしてください。

\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' 
]; 

答えて

0

あなたはファサード\Request\Inputのいずれかを使用する必要があり、要求フィールドへのアクセスを取得します。この場合、コードで簡単に任意のフィールドの値を取得することができます\Request::get('field1');

+0

ありがとうございます!ああそう:$ this->フィールド – Okay

関連する問題