Laravel Validator
程序员文章站
2022-06-01 20:02:38
Controller use Validator; public function Validators(){ $rules = [ 'title' => 'required|max:255', 'content' => 'required|max:255', 'field' => 'require ......
controller
use validator;
public function validators(){
$rules = [
'title' => 'required|max:255',
'content' => 'required|max:255',
'field' => 'required|max:255',
];
$messages = [
'title.required' => 'error message',
'content.required => 'content error message ',
'field.required' => 'field error message',
];
$validator = validator::make($request -> all(), $rules , $messages);
if($validator -> fails()){
return redirect('/path') -> witherrors($validator) -> withinput();
}
blade templement
@if($errors -> any())
@foreach($errrors -> all() as $error)
{{ $error }}
@endforeach
@endif
上一篇: 零容忍!百家号大规模封禁洗稿账户4.1万
下一篇: 怎么椅子还没到