多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
``` <form class="form-horizontal" method="post" action="{{url('student/create')}}"> {{csrf_field()}} <div class="form-group"> <label for="name" class="col-sm-2 control-label">姓名</label> <div class="col-sm-5"> <input type="text" name="student[name]" class="form-control" id="name" value="{{old('student')['name']}}" placeholder="请输入学生姓名"> </div> <div class="col-sm-5"> <p class="form-control-static text-danger">{{$errors->first('student.name')}}</p> </div> </div> <div class="form-group"> <label for="age" class="col-sm-2 control-label">年龄</label> <div class="col-sm-5"> <input type="text" name="student[age]" class="form-control" id="age" inputmode="{{old('student')['age']}}" placeholder="请输入学生年龄"> </div> <div class="col-sm-5"> <p class="form-control-static text-danger">{{$errors->first('student.age')}}</p> </div> </div> <div class="form-group"> <label class="col-sm-2 control-label">性别</label> <div class="col-sm-5"> <label class="radio-inline"> <input type="radio" name="student[sex]" {{ (isset(old('student')['sex']) && old('student')['sex'] == '0') ? 'checked' : '' }} value="0"> 未知 </label> <label class="radio-inline"> <input type="radio" name="student[sex]" {{ (isset(old('student')['sex']) && old('student')['sex'] == '1') ? 'checked' : '' }} value="1"> 男 </label> <label class="radio-inline"> <input type="radio" name="student[sex]" {{ (isset(old('student')['sex']) && old('student')['sex'] == '2') ? 'checked' : '' }} value="2"> 女 </label> </div> <div class="col-sm-5"> <p class="form-control-static text-danger">{{$errors->first('student.sex')}}</p> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-primary">提交</button> </div> </div> </form> ``` ***** ``` // 1.控制器校验 $this->validate($request,[ 'student.name'=>'required|min:4|max:20', 'student.age'=>'required|integer|max:150', 'student.sex'=>'required|integer' ],[ 'required'=>':attribute 为必填项', 'min'=>':attribute 长度不符合要求', 'integer'=>':attribute 必须为整数', 'max'=>':attribute 超过最大长度', ],[ 'student.name'=>'姓名', 'student.age'=>'年龄', 'student.sex'=>'性别', ]); // 2.Validator类验证 $validator=\Validator::make($request->input(),[ 'student.name'=>'required|min:4|max:20', 'student.age'=>'required|integer|max:150', 'student.sex'=>'required|integer' ],[ 'required'=>':attribute 为必填项', 'min'=>':attribute 长度不符合要求', 'integer'=>':attribute 必须为整数', 'max'=>':attribute 超过最大长度', ],[ 'student.name'=>'姓名', 'student.age'=>'年龄', 'student.sex'=>'性别', ]); if($validator->fails()){ return redirect()->back()->withErrors($validator)->withInput(); } ```