亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

無法返回“添加錯誤的提示”

添加成功的例子過了,但是添加錯誤的時候而比如不輸入年齡就直接會報錯,而不是返回頁面,

<!--?成功提示框?-->
@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">&times;</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">&times;</span>
????</button>
????<strong>失?。?lt;/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');
}


正在回答

1 回答

沒有添加驗證 ?需要在添加之前加入驗證?

$validator=\Validator::make($request->input(),[
????'student.name'=>'required|min:2|max:10',
????'student.age'=>'required|integer',
????'student.sex'=>'required|integer'
],[
????'required'=>":attribute不能為空",
????'integer'=>":attribute必須是整數",
????'min'=>':attribute最小不能少于2字符'
],[
????'student.name'=>'姓名',
????'student.age'=>'年齡',
????'student.sex'=>'性別'
]);
if($validator->fails()){
????return?redirect()->back()->withErrors($validator)->withInput();
}


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

無法返回“添加錯誤的提示”

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號