无法返回“添加错误的提示”
添加成功的例子过了,但是添加错误的时候而比如不输入年龄就直接会报错,而不是返回页面,
<!-- 成功提示框 --> @if(Session::has('success')) <div class="alert alert-success alert-dismissible"> <button type="buttn" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span> </button> <strong>成功!</strong>{{session::get('success')}}<!-- 操作成功提示 --> </div> @endif <!-- 失败提示框 --> @if(Session::has('error')) <div class="alert alert-danger alert-dismissible"> <button type="buttn" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span> </button> <strong>失败!</strong><!-- 操作失败提示 --> {{session::get('error')}} </div> @endif
public function save(Request $request){ $data=$request->input('student'); $student=new Studentm(); $student->name=$data['name']; $student->age=$data['age']; $student->sex=$data['sex']; if(!$student->save()){ return redirect('Student/index')->with('success','添加成功'); }else{ redirect()->back(); } return view('student.create'); }