Php Laravel 4:会话闪存消息在页面刷新时不会消失

Php Laravel 4:会话闪存消息在页面刷新时不会消失,php,flash,session,laravel-4,message,Php,Flash,Session,Laravel 4,Message,我对登录身份验证的get和post请求使用相同的方法,如 public function login() { if (Request::isMethod('post')){ // Getting credentials $username = Input::get('username'); $password = Input::get('password'); // Authenticating super admin

我对登录身份验证的get和post请求使用相同的方法,如

public function login()
{
    if (Request::isMethod('post')){
        // Getting credentials
        $username = Input::get('username');
        $password = Input::get('password');
        // Authenticating super admin
        if(Auth::attempt(array('email'=>$username,'password'=>$password,'sysadmin'=>1))){

            return Redirect::To('superadmin');
        }else{
            Session::flash('message', 'Invalid Credentials !'); 
            return View::make('superadmin::login');         
        }           
    }else{
        echo View::make('superadmin::login');
    }
}
这是显示错误消息的登录视图代码:

@if(Session::has('message'))
    <div class="alert-box message">
        <h2>{{ Session::get('message') }}</h2>
    </div>
@endif
@if(会话::has('message'))
{{Session::get('message')}
@恩迪夫
问题是当我在登录时输入无效凭据时,表单上会显示错误消息,但在手动刷新登录页面后,会话消息不会消失。其中,在第二次页面刷新时,会话消息消失

我知道这是因为URL(referer)在我的例子中保持不变,因为相同的方法“login”被用于两种类型的请求(get和post)


在这种情况下,显示错误消息的最佳方式是什么,以便在页面刷新时或消息自动消失。

这不是更好的选择吗

return View::make('superadmin::login')->with('message', 'Invalid credentials');
在你看来:

@if($message)
    <div class="alert-box message">
        <h2>{{ $message }}</h2>
    </div>
@endif
@if($message)
{{$message}}
@恩迪夫

这是因为您不需要闪存,因为闪存后从不使用重定向。

这是一个老问题,但我想解释一下最简单的方法:

@if(Session::has('message'))
    <div class="alert-box message">
        <h2>{{ Session::pull('message') }}</h2>
    </div>
@endif
@if(会话::has('message'))
{{Session::pull('message')}
@恩迪夫

我宁愿使用
Session:now()
而不是
Session:flash()
,就是这样。方法
now
立即闪烁消息以供立即使用。

我想了解更多有关此方法有效的原因,并
get
在下一页加载时将消息保留在会话中。