Session data persisting after flush
Created 7 years ago by jcastillotxSo I am creating a module where a person can add a child to sponsor. Since there are multiple children we have to treat it like a shopping cart. So I tried putting the kid in sessions and when I tried to clear the sessions the items were still there.
function add($childId) {
// Get Child Info (id, name, cost)
$child = $this->model->getChildInfo( $childId );
$children = array(
'id' => $childId,
'name' => $child->name,
'fee' => $child->fee
);
// Lets get it working
if ( $this->request->session()->exists( 'children' ) ) {
// Get Sessions
$sponsorships = $this->request->session()->get( 'children' );
if ( ! in_array( $children, $sponsorships ) ) {
$this->request->session()->push( 'children', $children);
}
} else {
$this->request->session()->put( 'children', $children );
}
$this->message->success( $child->name . ' was added to sponsor list' );
return back();
}
I have another function that when you sponsor the kids I have $this->request->session()->clear(); However, when I try to add more kids again the others are still there.
So here is what I am trying to do:
Function Add_Child
- Click button to add child to sponsorship (id is pushed to function)
- Grab child's information from database fusing id > name and sponsorship fee
- Add to sessions (if statement to make sure child doesnt already exist)
Function My_Children
- Pull from sessions the children we want to sponsor
- Send children to view to show in table
- Grab the sum of all the fees
Any help would be great
So when I go $this->request->session()->clear(); and it clears but when I remove that code the old session data is back. What is going wrong?
Sounds like maybe you're not sending back the request after the session is modified? Honestly you might find more help on this one from a Laravel resource cause Pyro really doesn't alter anything there - and last I used session data (not but a couple weeks ago) it worked just fine :-/ But I was working with it in the middleware.
I also had this issue now @jcastillotx . Reported it to Ryan so i think he is on it.
A quick fix is to run session()->save()
for now.
Where / how are you clearing your session? I am going to update your post to fix the formatting / use a more descriptive name...