在我的最后一个问题中,我正在寻求帮助,但错误填写的表格后会显示单个错误消息,而不是每个错误输入都会显示错误。他们很乐于助人,我收到了这段代码:
@if ($errors)
<span class='help-block'>
<strong>{{ "There are errors" }}</strong>
</span>
@endif
第二个答案是
@if (!empty($errors))
<span class='help-block'>
<strong>{{ "Some input field is not properly filled" }}</strong>
</span>
@endif
我认为以上内容将仅在表单提交后显示,并且Laravel将发现任何错误。问题是它总是像下面的屏幕快照中一样显示错误消息:
有人知道解决方案吗?非常感谢。
最佳答案
始终设置$errors
变量。这是一个message bag,可能包含也可能不包含消息。
您可以这样检查:
@if ($errors->count() > 0)
<span class='help-block'>
<strong>{{ "Some input field is not properly filled" }}</strong>
</span>
@endif
@if (!$errors->isEmpty())
也应该起作用。
关于php - Laravel在表单提交之前显示错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44618857/