Laravel 5.2 session flash 在本地主机上工作但在服务器上不工作?

Posted

技术标签:

【中文标题】Laravel 5.2 session flash 在本地主机上工作但在服务器上不工作?【英文标题】:Laravel 5.2 session flash working on localhost but not working on server? 【发布时间】:2017-02-17 05:48:34 【问题描述】:

Session flash 在本地工作正常,但在 Laravel 5.2 的服务器上不能工作?

在控制器中:

Session::flash('key', value");
return Redirect::to('/');

在视图中:

@if (Session::has('key') && Session::get('key')!='') 

alert('.......');

@endif

【问题讨论】:

确保在config/session.php.env 上配置了正确的驱动程序 什么是 'domain' => config/session.php 中的 null 【参考方案1】:

阅读:https://laravel.com/docs/5.2/responses#redirecting-with-flashed-session-data

Route::post('user/profile', function () 
    // Update the user's profile...

    return redirect('dashboard')->with('status', 'Profile updated!');
);

在视图/刀片中

@if (session('status'))
    <div class="alert alert-success">
         session('status') 
    </div>
@endif

【讨论】:

以上是关于Laravel 5.2 session flash 在本地主机上工作但在服务器上不工作?的主要内容,如果未能解决你的问题,请参考以下文章