如何在Laravel 5中的视图模板上显示会话数据 [英] How to display session data on view template in Laravel 5
本文介绍了如何在Laravel 5中的视图模板上显示会话数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Laravel 5的视图模板上显示会话数据.但是,它似乎什么也没显示.
I'm trying to display session data on a view template in Laravel 5. However it doesn't seem to show anything.
这是我用来设置会话的代码:
Here is the code i'm using to set the session:
Session::set('bookingConfirmed', BookingDates::where('id', Session::get('bookingFormData.slot.id'))->first());
这是我用来显示的代码:
Here is the code i'm using to display:
{{ Session::get('bookingConfirmed->time') }}
推荐答案
我猜是因为您已经在字符串中获得了对象的属性,该字符串标识了要获取的对象的键. IE.按如下方式移动->time
:
I'm guessing it's because you've got the attribute of the object within the string that identifies the key of the object you want to get. I.e. move ->time
as so:
{{ Session::get('bookingConfirmed')->time }}
您可能还需要首先检查它是否存在:
You may also want to check it exists firstly too:
@if(Session::has('bookingConfirmed'))
{{ Session::get('bookingConfirmed')->time }}
@endif
这篇关于如何在Laravel 5中的视图模板上显示会话数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文