如何在Laravel中的服务提供者中检索会话数据? [英] How to retrieve session data in service providers in laravel?

查看:92
本文介绍了如何在Laravel中的服务提供者中检索会话数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Laravel项目.我正在使用Laravel 5.1.在我的项目中,我以这种方式将数据共享给appServiceProvider的启动方法中的所有视图.

I am developing a Laravel project. I am using Laravel 5.1. In my project, I am sharing data to all view in boot method of appServiceProvider in this way.

function boot()
{
    $items = $this->itemRepo->getItems(session("key"));
    view()->share('items', array('items'=>$items));
}

但是会话值始终为null.我在网上看到很多文章.但是他们没有工作.如何将会话值传递到那里?

But session value is always null. I saw a lot of article online. But they were not working. How can I pass my session value to there ?

推荐答案

我认为您的问题在以下帖子中得到了回答 在应用程序启动过程中无法访问Laravel 5会话数据 ,您可以使用 添加的 Taylor Otwell 这样的中间件会话开始会话的事件 没有会话,因为没有HTTP请求.

I think your question answered in the following post Laravel 5 session data is not accessible in the app boot process, You could use middleware like Taylor Otwell said in Add event for session started conversation There is no session because there is no HTTP request.

希望这会有所帮助.

这篇关于如何在Laravel中的服务提供者中检索会话数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆