2017-04-23 6 views
0

Guys 我正在使用laravel5.2.45。當我使用redirect()->with()routes.php內有閃存數據時,我無法輸出緩存數據。這是我的代碼。在laravel中使用redirect() - > with()時無法輸出Flash數據5.2.45

App/Http/routes.php

Route::get('hello', function(){ 
     return redirect('/')->with('ok',"success"); 
    }); 

index.blade.php

<div class="container"> 
     @if(session()->has('ok')) 
     <?php echo session('ok'); ?> // always null 
     @endif 
    </div> 

沒有mattter我做什麼,也不能打印會話數據。我也嘗試使用`Session :: get('ok')',但它仍然是空的。

我已經更新了我的應用程序composer updatecompose dump-autoload,但它仍然不起作用。

任何人都可以幫忙嗎?

+0

你申請'web'中間件的路線? –

+0

會話的驅動程序是什麼? –

回答

0

這是我建議你還是...通過創建幾個測試路線的開始..

Route::get('/test', function() { 
    return redirect('/test2')->with('ok', 'Working'); 
} 

Route::get('/test2', function() { 
    return session('ok'); 
} 

如果這工作那麼你的會議是工作的罰款。如果沒有,請檢查以確保您有一個Web中間件(不是零而不是兩個)。你可以這樣做php artisan route:list

另一種可能是它是由多個重定向引起的,我已經看到了很多。如果是這樣的話,只需第一次重定向後刷新

您可以找到的文檔中的詳細信息:https://laravel.com/docs/5.2/session#flash-data

+0

謝謝,我解決了這個問題。不工作的原因是因爲我使用了'web'中間件。現在,當我刪除「網絡」中間件後,它運行良好 – Sawyer

相關問題