Search code examples
phplaravelsessionlaravel-5.3

How to set sessions in Laravel 5.3


I am trying to use sessions in Laravel PHP

I used this

Session::set('store_id', $store->store_id); Session::set('user_id', $store->id);

and used them like

Session::get('store_id')

I used class like use Session;

But I am getting error

FatalErrorException in Manager.php line 137: Call to undefined method Illuminate\Session\Store::set()

What is it saying and how do I resolve it?


Solution

  • You should use put() or push() methods. Or just use the session() helper. Set the data:

    session(['store_id' => $store->store_id]);
    

    Get the data:

    session('store_id');