phplaravelsessionhttp-redirectlaravel-5

Laravel 5.2: Flash values in session gone after redirect


I use Laracasts Flash package to display flash messages to my users. But there's a problem: flash values are gone after one redirect. Values which I set with Session::set(); are still there. I use the web-middleware on every controller and it even includes the StartSession class. Even redirects->withInput are gone after the redirect.

Here's my controller:

public function update(Request $request) {
    $profile = Auth::user()->profile;

    $validator = Validator::make($request->all(), [
        'email' => ['email', 'unique:profiles,email,' . $profile->id, 'max:255'],
    ]);

    if($validator->fails()) {
        var_dump("failed");
        return redirect()->back()->withInput($request->input())->withErrors($validator);
    }

    $profile->update($request->input());
    $profile->save();

    Flash::success('saved');
    \Session::set('test', 'testvalue');
    return redirect()->route('profile.edit');
}

Here's the method where I try to get the value:

public function edit() {
    $account = Auth::user();

    var_dump(\Session::all());
    return view('profile.edit', [
        'account' => $account,
        'profile' => $account->profile,
    ]);
}

The testvalue still exists but the flash message is gone. Even if I try to set them myself with Session::flash();

Any idea what to do?


Solution

  • I found the answer: Taylor Otwell made some changes at the route service provider. Now every route has the web-middleware applied by default. Assigning it again like I had to before this update (23. March 2016) will discard the flash values.

    So: Remove every manual web-middleware assignment. Then It'll work.