Session data persisting after flush

jcastillotx - 9 months ago

So 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();

}

ryanthompson - 9 months ago

Where / how are you clearing your session? I am going to update your post to fix the formatting / use a more descriptive name...

jcastillotx - 9 months ago

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.

jcastillotx - 9 months ago

So here is what I am trying to do:

Function Add_Child

  1. Click button to add child to sponsorship (id is pushed to function)
  2. Grab child's information from database fusing id > name and sponsorship fee
  3. Add to sessions (if statement to make sure child doesnt already exist)

Function My_Children

  1. Pull from sessions the children we want to sponsor
  2. Send children to view to show in table
  3. Grab the sum of all the fees

Any help would be great

jcastillotx - 9 months ago

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?

ryanthompson - 9 months ago

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.