控制器当中
public function create(Request $request){
if($request->isMethod('POST')){
$data = $request->input('Student');
if(Member::create($data)){//批量赋值
return redirect('student/index')->with('success','添加成功');
}else{
return redirect()->back();
}
}
return view('student.form');
}
在 view界面
<!-- 成功提示框 -->
@if (Session::has('success'))
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" 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" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<strong>失败!</strong> {{ Session::get('error') }}
</div>
@endif
路由当中
Route::group(['middleware' => ['web']], function () {
Route::get('student/index',['uses'=>'StudentController@index']);
Route::any('student/create',['uses'=>'StudentController@create']);
Route::any('student/save',['uses'=>'StudentController@save']);
});
添加成功,没有提示
解决办法,不要用中间件
Route::get('student/index',['uses'=>'StudentController@index']);
Route::any('student/create',['uses'=>'StudentController@create']);
Route::any('student/save',['uses'=>'StudentController@save']);