0

I had a controller and in it I am storing a session value like this

if(!Session::isStarted())
   Session::start();
}
Session::put('total', $total);

In the view I'm trying to retrieve this value:

if(!Session::isStarted()){
    Session::start();
}
var_dump(Session::all());  // <-- value 'total' not showing

This is the output of the session

array(2) { ["_token"]=> string(40) "IzsMtiTOfMpoOzLj53YyMYEMAUHr4mLMnIAWcnaJ" ["flash"]=> array(2) { ["old"]=> array(0) { } ["new"]=> array(0) { } } } 
2
  • What session driver are you using? Commented Apr 11, 2014 at 18:33
  • I already solved!, I just needed to put Session::save() (I'm using file driver) Commented Apr 11, 2014 at 22:08

1 Answer 1

1

You don't need to use this:

if(!Session::isStarted())
    Session::start();
}

The session will be started by framework, you can simply use this:

Session::put('total', $total);

All you need to configure/set the driver in app/config/session.php file and by default Laravel uses file driver, it is set in the app/config/session.php like this:

'driver' => 'file',

Laravel 4 not passing session value from controller to view

Actually you don't need to pass the session, if you set the session anywhere in your application then it'll be available in anywhere through your application, you can access it from your view, you don't need to pass it but you have to set/put the value in the session before you access it.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the tip, the only thing I was missing is to save the session data like Session::save()
Welcome :-) Btw, I think you need to read the documentation and also if you have confusing about session in PHP then you should read the PHP manual.
Yes I check the documentation but it says nothing about the save() method.
It's because that is not required by a end user We don't need to start or stop it, it's framework's responsibility, we just need to tell which driver we want to use.
I'm talking about the save method not Session::start()
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.