[英]Validate() message is not working in laravel
我的驗證工作正常。 但沒有顯示任何消息。 我在下面提到。
在 controller
$fields = collect([
'monthly_fees',
'admission',
'due_advance',
'session_fee',
'library',
'sports',
'poor_funds',
'fine',
'reciept',
'milad',
'scout',
'development',
'registration',
'f_tutorial',
's_tutorial',
't_tutorial',
'f_exam',
's_exam',
't_exam',
'labratory',
'transport',
'syllabus',
'certificate',
'testimonial',
'generator',
'extra'
]);
$rules = $fields->mapWithKeys(function ($field) use ($fields) {
return [
$field => 'required_without_all:' . $fields->reject(function ($item) use ($field) {
return $item == $field;
})->implode(',')
];
})->toArray();
$this->validate($request, $rules);
在視圖中
@if (count($errors) > 0)
<div class="alert alert-danger">
<ul class="text-center">
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
我也在 controller 中使用了這些代碼行,但沒有用。
if($this->validate()->fails()) {
return redirect()->back()->with('error','Please Input minimum 1 field...');
}
我想做至少 1 個字段是必需的。 我有 26 個輸入字段。 我總是將這些代碼用於一次性使用。 但這次要驗證所需的最少一個字段。 這些代碼驗證了所需但沒有顯示任何消息,盡管我提到了刀片中的錯誤。 你能幫我解決這些錯誤嗎? 提前致謝。
我解決了我的問題。 這里我使用了 $this->vatidate(...); 這對我來說是錯誤的。 然后我使用了驗證器 package 並在失敗時返回帶有重定向的自定義消息。 然后它工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.