無法返回“添加錯(cuò)誤的提示”
添加成功的例子過了,但是添加錯(cuò)誤的時(shí)候而比如不輸入年齡就直接會(huì)報(bào)錯(cuò),而不是返回頁面,
<!--?成功提示框?--> @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'); }
2020-04-03
沒有添加驗(yàn)證 ?需要在添加之前加入驗(yàn)證?