2016-09-04 71 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-> field – Okay

相關問題