clat23
2 years ago
5771
11
Laravel

Session variables not saving / persisting after redirect

Posted 2 years ago by clat23

Comment.php

public function store($data)
    {
        $comment = new Comment;
        $comment->title = $data->title;
        $comment->body = $data->body;
        $comment->save();
        session(['commentTitle' => $data->title]);
        session(['commentBody' => $data->body]);
        dd(session('commentTitle')); // This dumps the title string as expected...
        return redirect()->action('[email protected]');
    }

CommentsController.php

public function index()
{
    $comments = Comment::get();

    dd(session('commentTitle')); // This dumps null...?

    return view('/comments/index')->with([
        'comments' => $comments,
    ]);
}

Any idea why the session variables are not persisting?

Please sign in or create an account to participate in this conversation.