Laravel 5重定向消息

Čam*_*amo 5 php redirect laravel laravel-5 laravel-5.2

有人可以解释为什么当重定向到另一个页面时,下面的代码不起作用?

return redirect()->route('homepage')->with('message', 'I am so frustrated.');
Run Code Online (Sandbox Code Playgroud)

重定向按预期工作,但不显示该消息.

视图看起来像:

@if ( session()->has('message') )
    <div class="alert alert-success alert-dismissable">{{ session()->get('message') }}</div>
@endif
Run Code Online (Sandbox Code Playgroud)

当我将其更改为:

return redirect()->route('contact')->with('message', 'I am so frustrated.');
Run Code Online (Sandbox Code Playgroud)

,与redirect() - > back()相同,一切正常,并显示消息.重定向back()to()另一个视图有什么区别?

pat*_*cus 5

如果您使用的是Laravel 5.2,请确保您使用该访问会话数据的所有路由都包含在web中间件组中.

如果您的contact路由在web中间件组内,但您的homepage路由不在,则可以解释您的问题.