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'
];
謝謝您的幫助!哦,是的:$ this-> field – Okay