【问题标题】:Laravel redirect()->with('status','My message') errorLaravel redirect()->with('status','My message') 错误
【发布时间】:2017-01-13 06:27:36
【问题描述】:

我在 Laravel 5.2 上创建了一个电子邮件验证。当用户填写注册表并通过验证时,他们会将用户返回到登录表单:

return redirect('/login')->with('status','We send a email verification, please
confirm.');

这很完美。问题是当用户点击收件箱中的链接验证时,他们激活了帐户并重定向到管理页面,但没有状态消息。这是 AuthController.php 中的代码:

public function activateUser(Request $request,$token)
{
    if ($user = $this->activationService->activateUser($token)) {
       return redirect('/login')->with('status','You account is now activated. Please login.');
    }
    abort(404);
}

在我的 login.blade.php 上:

@if (session('status'))
    <div class="alert alert-success">
        {{ session('status') }}
    </div>
@endif

请问,有人知道为什么会话变量不起作用吗?

谢谢。

【问题讨论】:

  • 你能把代码显示在你想显示消息的地方吗?
  • 尝试将 if ($user = $this->activationService->activateUser($token)) 更改为 if ($user == $this->activationService->activateUser($token))。您的 if 语句中有单 = 登录。
  • @RuhulAmin 我再次编辑检查我的代码。谢谢。
  • @boroboris 我改变了它并说它的 $user 变量没有定义。

标签: laravel laravel-5.2


【解决方案1】:

好吧,我不知道这里发生了什么以及为什么 redirect()->with() 不起作用。我解决了一个名为activated.blade 的新视图,它是login.blade 的副本,但有一条消息说:“您的帐户现已激活。请登录。”所以我在控制器中这样做:

return redirect('/激活');

【讨论】:

    【解决方案2】:

    它应该像这样工作。在您的AuthController 中,只需更改

      return \Redirect::to('/login')->with('status','You account is now activated. Please login.');
    

    在你的login.blade

     @if (Session::has('status'))
           <div class="alert alert-success" role="alert">
                <p>{{ Session::get('status') }}</p>
           </div>
     @endif
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-24
      • 1970-01-01
      • 1970-01-01
      • 2022-10-24
      • 1970-01-01
      • 2016-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多