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') }}
The session configuration file is stored at config/session. php . Be sure to review the well documented options available to you in this file. By default, Laravel is configured to use the file session driver, which will work well for many applications.
There are various ways of passing data to views:By using the name array. By using with() function. By using compact() function.
To access the session data, we need an instance of session which can be accessed via HTTP request. After getting the instance, we can use the get() method, which will take one argument, “key”, to get the session data.
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
You might want to try first getting the object and then get the fields of it like this
{{ Session::get('bookingConfirmed')->time }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With