You don't need to start a Session, Laravel takes care of that for you. The Session Facade (that you were trying to use) wraps this automatically generated Session and helps you access it.
use Session; is wrong because the Session Facade is not in the same directory as your controller. You have to use use Illuminate\Support\Facades\Session; at the top of the page (but behind the line namespace App...;)
If the Session still isn't persistent there should be a problem with the webserver.
You don't need to start a Session, Laravel takes care of that for you. The Session Facade (that you were trying to use) wraps this automatically generated Session and helps you access it.
Thank you for the suggestions! Does Laravel start a session no matter what? Session file is generated even when I comment out all the related code. Difference is whether my session variables appear in the file. New session file is still being generated every time I refresh page.
use Session; is wrong because the Session Facade is not in the same directory as your controller. You have to use use Illuminate\Support\Facades\Session; at the top of the page (but behind the line namespace App...;)
As you suggest, I replace 'use Session' with 'use Illuminate\Support\Facades\Session' and also place it in the other php file where I try to access the session variables. It doesn't help to resolve the 'class Session not found' error it throws. I looked up the 5.1 API page, there is also 'Illuminate\Session' (http://laravel.com/api/5.1/Illuminate/Session.html). How does one know which namespace to use? This page(http://laravel.com/docs/5.1/session) makes no mention of it either.
You mentioned that the 'use Illuminate\Support\Facades\Session' to be placed behind the line namespace App. What is the reason behind it?
If the Session still isn't persistent there should be a problem with the webserver.
There might indeed be a problem with XAMPP. Someone said that after a fresh installation, the not persisting problem went away. I will save this option for last.
Thanks for your help again!
Found out a way to resolve the problem in my case. I have all the lines of code removed in my index.blade.php, have it saved and reloaded in the browser. Paste the code back and reload again, the generation of session files stops. No idea what is happening here.
If you're working with an IDE like phpStorm or NetBeans you will get suggestions as you start typing a classname. If you choose a suggestion from the autocomplete it will automatically add the use ... code that fits the chosen class.
Otherwise you'll just have to know. :) That's the problem with namespaces.
The namespace command has to be the first thing in the php file. It defines in which "directory" all the classes in the file live. So when you try to access a class inside of your PHP file it will look in its own namespace first. To tell him that a class lies in a different namespace you'll have to put the whole name like $session = new \Illuminate\Session(); To save the hassle of typing there are the use statements where you basically say "If I use the Session class please take this one".
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community