Laravel 登录后重定向回上一页

4

如何在Laravel 5.2中登录后重定向回原页面?

AuthController

protected $redirectTo = '/';

重定向用户

<?php

namespace Illuminate\Foundation\Auth;

trait RedirectsUsers
{
    /**
     * Get the post register / login redirect path.
     *
     * @return string
     */
    public function redirectPath()
    {
        if (property_exists($this, 'redirectPath')) {
            return $this->redirectPath;
        }

        return property_exists($this, 'redirectTo') ? $this->redirectTo : '/';
    }
}

2
只需在登录函数中添加 return redirect()->back(),就可以了。只要确保不会陷入重定向循环即可。 - Andrei
@Andrew 我应该在哪里添加这段代码?我在 Laravel 5.2 中使用了 make:auth。 - jungmyung
请参考此答案:https://dev59.com/Ll0a5IYBdhLWcg3wxrOM#56095470 - Akash Sethi
2个回答

0

你可以使用以下两个选项之一来完成。

  • return Redirect::back(); 这将带用户返回他/她上一个页面。
  • return redirect('输入你的路由'); 这将带用户到你在该特定路由中定义的视图。

1
我应该在哪里添加这段代码?我在 Laravel 5.2 中使用了 make:auth。 - jungmyung

0
在你编写的控制器中的认证函数中,它会类似于这样:
 function xyz() {

  // your function code

  return Redirect::back();
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接