[英]validation message is not appearing properly
在validation.php 文件中,錯誤信息是這樣的:
'after_or_equal' => 'A :attribute must be a date after or equal to :date.',
但是,當發生此錯誤時,出現的消息是:
validation.after_or_equal
你知道為什么嗎?
在視圖中顯示消息的代碼:
@if ($errors->any())
<div class="alert alert-danger mt-3">
<ul>
@foreach ($errors->all() as $error)
<li class="text-danger">{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
帶有驗證的存儲方法:
public function store(Request $request)
{
$this->validate($request, [
'startDate' => 'required|date_format:d F Y - H:i',
'endDate' => 'required|date_format:d F Y - H:i|after_or_equal:startDate',
]);
}
查看包含錯誤文件:
@extends('layouts')
@section('content')
<div class="container-fluid px-4">
@include('includes.errors')
<form id="edit_admins" method="post" class="clearfix"
action="{{route('admins.update', ['post_id' => $post->id])}}" enctype="multipart/form-data">
{{csrf_field()}}
....
</form>
@endsection
所以確認你把你的代碼放在哪里'after_or_equal' => 'A :attribute must be a date after or equal to :date.',
,因為如果你把你的代碼放在那里你會收到這個消息validation.after_or_equal
。 你需要把這個地方放在validation.php 上:
<?php
return [
/*
|------------------------------------------------------------------------
| Validation Language Lines
|--------------------------------------------------------------------------
|
| The following language lines contain the default error messages used by
| the validator class. Some of these rules have multiple versions such
| as the size rules. Feel free to tweak each of these messages here.
|
*/
'accepted' => 'The :attribute must be accepted.',
'active_url' => 'The :attribute is not a valid URL.',
'after' => 'The :attribute must be a date after :date.',
'after_or_equal' => 'A :attribute must be a date after or equal to :date.',
...
如果一切正常,請檢查您的應用區域設置,也許您使用的是另一種語言。
問題似乎是date_format
驗證規則應該將日期格式用"
date_format
起來。
這是更新的片段。
public function store(Request $request)
{
$this->validate($request, [
'startDate' => 'required|date_format:"d F Y - H:i"',
'endDate' => 'required|date_format:"d F Y - H:i"|after_or_equal:startDate',
]);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.