php 如何在 Laravel 5 中的视图模板上显示会话数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30595350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 21:54:38  来源:igfitidea点击:

How to display session data on view template in Laravel 5

phpsessionlaravel-5

提问by V4n1ll4

I'm trying to display session data on a view template in Laravel 5. However it doesn't seem to show anything.

我正在尝试在 Laravel 5 中的视图模板上显示会话数据。但是它似乎没有显示任何内容。

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') }}

回答by haakym

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 ->timeas so:

我猜这是因为您在字符串中获得了对象的属性,该属性标识了您想要获取的对象的键。即移动->time如下:

{{ Session::get('bookingConfirmed')->time }}

You may also want to check it exists firstly too:

您可能还想先检查它是否存在:

@if(Session::has('bookingConfirmed'))
    {{ Session::get('bookingConfirmed')->time }}
@endif

回答by Margus Pala

You might want to try first getting the object and then get the fields of it like this

您可能想尝试先获取对象,然后像这样获取它的字段

{{ Session::get('bookingConfirmed')->time }}