会议不在Laravel 5上工作

I am trying to get session working on Laravel 5 but it seems like it doesn't work. I have followed this section of the documentation, but I can get the data to display. Here's my controller code:

public function store($id)
{
        // some code
        return redirect('/')->with('err', 'The error.');


        } 

The code in the view:

@if (session('err'))
<div class="alert alert-danger">
    {{ session('err') }}
</div>
@else
<p>Doesnt work</p>
@endif

So the Doesnt work paragraph showing up. I have tried various cache settings (file, Redis, etc.) but nothing seems to work. Any ideas?

What you want to do is this:

Using your code.

Controller

public function store($id)
{
    // some code
    return redirect('/')->with('err', 'The error.');
} 

View

@if ($err)
    <div class="alert alert-danger">
        {{ $err }}
    </div>
@else
    <p>Doesn`t work</p>
@endif

Using Session::flash();

Controller

public function store($id)
{
    Session::flash('err', 'The error.');
    return redirect('/');
} 

View

@if (session('err'))
    <div class="alert alert-danger">
        {{ session('err') }}
    </div>
@else
    <p>Doesn`t work</p>
@endif

I have found the solution. Seems like the session data was getting lost in the redirection. All I had to do was include this in the target controller:

$request->session()->reflash();

Thanks for the help!

you can also add one line before you redirect
session::save();