我是Laravel 5.2的新用户我正在尝试使用会话闪存来显示警报
以下是会话flash的代码
DepartmentContoller.php
public function add(Request $request ){
if($request->isMethod('post'))
{
$department = new Department;
/*$department->department_name = $request->department_name;
$department->status = $request->status;
$department->save();*/
$department->create($request->all());
$request->session()->flash('alert-success', 'User was successful added!');
return redirect('admin/departments');
}
return view('admin.department.add');
}
这是我要显示会话闪存值的视图文件
@foreach (['danger', 'warning', 'success', 'info'] as $msg)
{{Session::has('alert-' . $msg)}}
@if(Session::has('alert-' . $msg))
<div class="alert alert-{{$msg}} alert-dismissible">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
<h4><i class="icon fa fa-ban"></i> Alert!</h4>
{{session('alert-'. $msg)}}
</div>
@endif
@endforeach
这是我的路线deatail
Route::group(['middleware' => ['web']], function () {
//Login Routes...
Route::get('/admin', 'AdminAuth\AuthController@showLoginForm');
Route::get('/admin/login','AdminAuth\AuthController@showLoginForm');
Route::post('/admin/login','AdminAuth\AuthController@login');
Route::get('/admin/logout','AdminAuth\AuthController@logout');
// Registration Routes...
Route::get('admin/register', 'AdminAuth\AuthController@showRegistrationForm');
Route::post('admin/register', 'AdminAuth\AuthController@register');
Route::group(['as' => 'admin', 'middleware' => ['admin', 'web'], 'prefix'=>'admin'], function () {
Route::get('/admin', array('uses'=>'AdminController@index'));
Route::get('/departments', array('as' => 'departments', 'uses'=>'DepartmentController@index'));
Route::get('/department/add', array('as' => 'add', 'uses'=>'DepartmentController@add'));
Route::post('/department/add', array('as' => 'add', 'uses'=>'DepartmentController@add'));
});
});
我想在视图中显示成功提醒,但我没有在我的视图页面上获取会话值。请告诉我哪里出错?
答案 0 :(得分:0)
Route::group(['middleware' => 'web'], function () {
// routes here
Route::get('/departments', array('as' => 'departments', 'uses'=>'DepartmentController@index'));
});