1

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.

1 Answer 1

4

Use the session's push method:

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

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

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

3 Comments

When I use push I get this error: [] operator not supported for strings
@Lynx Use push always if you want to store multiple items in the key. Because if you start to store string, numbers, you can't make array from the value.
That's what it was. Once I cleared the storage it started working. Thanks mate!

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.