我开始研究Laravel 7.x,但收到验证错误。运行下面的代码,我得到“开始日期不是有效的日期”。和“结束日期不是有效日期”。我该如何解决?
web.php:Route::post('/store-fast-event', 'fastEventsController@storeFastEvent')->name('routeStoreFastEvent');
event.js:
let id = $("#modalFastEvent input[name='id']").val();
let title = $("#modalFastEvent input[name='title']").val();
let start = $("#modalFastEvent input[name='start']").val();
let end = $("#modalFastEvent input[name='end']").val();
let color = $("#modalFastEvent input[name='color']").val();
let FastEvent = {
title : title,
start : start,
end : end,
color : color,
}
route = routeFastEvents('routeStoreFastEvent');
sendFastEventRoute(route, FastEvent);
})
Request.php:
public function rules()
{
return [
'title' => 'required | min:3',
'start' => 'date:H:i:s | before:end',
'end' => 'date:H:i:s | after:start',
];
}
public function messages()
{
return [
'title.required' => 'Preencha o campo Título',
'title.min' => 'O título deve conter no mínimo 3 caracteres',
'start.date' => 'The start is not a valid date',
'start.before' => 'A hora inicial deve ser anterior a hora final',
'end.date' => 'The end is not a valid date."',
'end.after' => 'A hora final deve ser posterior a hora inicial',
];
}
php请求将以Y-m-d的格式传递日期(检查您的请求标头)。因此,在您的验证中使用
'start' => 'date|after_or_equal:' . now()->format('jS F Y'), // accepts >= today
'end' => 'data|after:start' // accepts > start