Laravel's session key is zero after entering a session

I have a wired problem. Im put some string / object into the session, and when I want to get it, it is not.

This is the code:

class CartController extends \BaseController
{

    public function index()
    {
        return Session::all(); // items is not there
    }

    public function store()
    {
        Session::put('items', Input::get('items'));
    }

}

in angular:

this.saveItemsToSession = function() {
    $http.post('cart', {
      items: 'test even string'
    });
  };

What can cause this problem?

Session does not seem to work. This method works:

session_start();
class CartController extends \BaseController
{

    public function index()
    {
        return $_SESSION['items'];
    }

    public function store()
    {
        $_SESSION['items'] = Input::get('items');
    }

}
+4
source share
3 answers
    Session::all()

returns an array of all session variables, and

    $_SESSION['items']

returns a session of "elements", and both outputs are different from each other. To obtain

    $_SESSION['items']

Meaning Here are a few ways:

    Session::all()['items']

or

    Session::get('items')
0
source

From laravel docs: https://laravel.com/docs/master/routing

, , CSRF, , , , . , :

Route::group(['middleware' => ['web']], function () {
     //all routes
});

, .

0

Do you use subdomains?

-1
source

All Articles