php - 验证器不使用 Laravel 中的输入类型日期
问题描述
我是 Laravel 6 的新手。我制作了一个应用程序来创建会议。用户通过具有许多输入的表单创建会议,并且在控制器中有一个验证器,用于检查输入是否已填写。除了两个输入类型时间(“开始”和“结束” )。当我提交表单并将其中一个字段留空时,验证器无法正常工作,因为它出现了异常消息:
InvalidArgumentException Illegal operator and value combination.
此外,在开发人员工具中出现以下错误:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
我尝试对这两个字段进行更改required
,required|date_format:H:i
但效果不佳。我什至尝试删除 CheckTime,这是一个自定义规则,用于检查会议结束是否在开始之后,但我失败了。
输入“开始”
<label for="start" class="col-sm-2">Start Hour:</label>
@if (old('start') !== null)
<input type="time" class="form-control col-sm-6" id="start" name="start" value="{{ old('start') }}">
@elseif (isset($id))
<input type="time" class="form-control col-sm-6" id="start" name="start" value="{{ $meeting->start_hour }}">
@else
<input type="time" class="form-control col-sm-6" value = "{{ old('start') }}" id="start" name="start">
@endif
输入“结束”
<label for="end" class="col-sm-2">End Hour:</label>
@if (old('end') !== null)
<input type="time" class="form-control col-sm-6" id="end" name="end" value="{{ old('end') }}">
@elseif (isset($id))
<input type="time" class="form-control col-sm-6" id="end" name="end" value="{{ $meeting->end_hour }}">
@else
<input type="time" class="form-control col-sm-6" value = "{{ old('end') }}" id="end" name="end">
@endif
验证器:
public function insert_meeting(Request $request)
{
$this->validate($request, [
'participants' => [ 'required', new CheckParticipantInsert() ],
'description' => 'required',
'room' => [ 'required', new CheckRoomInsert() ],
'date_meeting' => [ 'required', new CheckDateTime() ],
'start' => [ 'required', new CheckTime() ],
'end' => 'required',
]);
$participants_mail = $this->convertIdToName(request('participants'));
$mail_response = $this->send_mail_create($request, $participants_mail);
$meeting = new Meeting();
$participants = request('participants');
$meeting->id_participants = implode(';', $participants);
$meeting->description = request('description');
$meeting->id_room = request('room');
$meeting->date = request('date_meeting');
$meeting->start_hour = request('start');
$meeting->end_hour = request('end');
$meeting->save();
if($mail_response) {
$message_correct = "The meeting has been correctly inserted. The emails to advise the participants have been sent.";
return redirect()->route('home')->with('success', $message_correct);
} else {
$message_correct = "The meeting has been correctly inserted.";
$mail_not_sent = "The emails to advise the participants could not be sent";
return redirect()->route('home')->with('success', $message_correct)->with('mail_not_sent', $mail_not_sent);
}
}
从理论上讲,这两个字段都是必需的,所以我不明白为什么会出现异常错误以及为什么验证器不会在视图中简单地显示类似的消息:The start field is required
或 . The end field is required
. 有人可以帮助我吗?
解决方案
推荐阅读
- sql - 创建日期字段的开始日期和结束日期
- java - 将枚举映射到 Android 中的资源字符串
- vim - 在 R 中运行代码时更改“$”的 Vim 输出
- parse-server - 需要帮助将云代码部署到 Parse 平台
- java - 如何在Android中动态地将MenuItem添加到带有图标和标题的NavigationView?
- reactjs - 如何使用 jest 监视 setState 并测试 toHaveBeenCalled()
- javascript - 如何根据日期属性对项目列表进行排序?
- google-fusion-tables - 多个FusionTableLayer和样式
- spring - 使用 Elasticsearch 和 Spring Data 对新闻源进行优先级排序
- html - 任何可以帮助我将 XML 文件转换为 docx 文件的工具?