Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Amalmax's avatar

how to save session data in to table

I need to save following session value to same table with new column as project_name.

 session(['project_name' => $this->getProjectName($id),
                'user_email' => $this->getEmail($collaborator_username)
        ]);

My existing Controller is

public function addCollaborator(Request $request, $id, Collaboration $collaboration)
    {
       $this->validate($request, [
            'collaborator'     => 'required|min:5',
        ]);

       $collaborator_username           = substr(trim($request->input('collaborator')),1);
       $collaboration->project_id       = $id;
       if( is_null($this->getId($collaborator_username)))
       {
            return redirect()->back()->with('warning', 'This user does not exist');
       }

       $collaborationStatus = $this->isCollaborator($id, $this->getId($collaborator_username));
       if(! is_null($collaborationStatus))
       {
            return redirect()->back()->with('warning', 'This user is already a collaborator on this project');
       }
       

       $collaboration->collaborator_id  = $this->getId($collaborator_username);
       
      

       session(['project_name' => $this->getProjectName($id),
                'user_email' => $this->getEmail($collaborator_username)
        ]);

       $collaboration->save();

       return redirect()->back()->with('info', "{$collaborator_username} has been added to your project successfully");
    }
0 likes
2 replies
bobbybouwmann's avatar
Level 88

Not really sure what you want to do.. I have the feeling you have no clue about what you are about to do..

Anyway for your problem this should fix it right?

$collaboration->project_name = $this->getProjectName($id);

Make sure your table has the project_name column

1 like

Please or to participate in this conversation.