2016-02-02 20 views
-1

我在Laravel使用閃光燈的工作,顯示小的通知這裏是我的功能看起來像:我的會話即顯信息不會在Laravel

public function movetotrash($id){ 

     $page = Pages::where('id', $id) -> first(); 
     $page -> active = 0; 
     //$page -> save(); 
     \Session::flash('flash_message', 'Post has been successfully moved to trash'); 
     return redirect('pages'); 
} 

這是我的看法是如何的樣子:

<div class="col-md-12"> 

        @if(Session::has('flash_message')) 
         <div class="alert alert-success"> 
           {{Session::get('flash_message')}} 
         </div> 
        @endif 
</div> 

這裏是我的路線看起來像:

Route::get('/', function() { 
    return view('welcome'); 
}); 

Route::get('dashboard', function() { 
    return view('dashboard.dashboard'); 
}); 

Route::get('pages/trash', '[email protected]'); 

Route::get('pages/movetotrash/{id}', '[email protected]'); 

Route::resource('pages', 'PagesController'); 

我是否需要調用一些庫在我的控制器Session工作?

謝謝! (提前)

回答

0

從laravel文檔:https://laravel.com/docs/master/routing

不放在網絡中間件組內的任何路線不會有 訪問會議和CSRF保護,所以請確保 需要這些的任何路由功能放在組中。通常情況下,你會 最到位的路線該組中:

Route::group(['middleware' => ['web']], function() { 
    //all routes 
}); 

把你的路由裏面中間件和您的問題將解決。

+0

Ohk!讓我試試這個。 – user3201500

+0

明白了!它的解決,像魅力工作... – user3201500