Lynx
Lynx

Reputation: 1482

Adding multiple values to Laravel Session

I am trying to figure out the best way to accomplish this issue.

I have a Session that's triggered when someone visits a number amount of pages.

When they visit the page the Session should add that page ID to the history session. Then when they go to the history page all of the pages they went to will show up in a array

What's happening though is everytime I use Session::put('history', $inventory->id); it's being overwritten by whichever page is the newest.

Here is how I am calling it: Session::get('history')

So basically I will get this returned:

string '1111111' (length=8)

I never had to have more than one value in a Session before and I couldn't find anything related to it in the docs. Looks like it needs to be saving as an array but not sure how I can do this.

Upvotes: 1

Views: 2794

Answers (1)

Joseph Silber
Joseph Silber

Reputation: 219938

Use the session's push method:

Session::push('history', $inventory->id);

Then when you retrieve it you'll get an array of values.

Upvotes: 4

Related Questions