Laravel 5 Auth登录后注册 [英] Laravel 5 Auth Register After Login

查看:103
本文介绍了Laravel 5 Auth登录后注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Laravel 5中登录后,我试图创建用户.注册路由为

I am trying to create users after login in Laravel 5. Register route is

get('auth/register', 'Auth\AuthController@getRegister');

无论有没有登录,都应该可以访问它,因为我没有使用任何中间件.但是,当我尝试登录时登录到auth/register时,它会将我重定向到/home.我只能在登录前访问它.

It should be accessible with or without login as I have not used any middleware in it. But when I try to navigate to auth/register if logged in then It redirects me to /home. I can only access it before login.

登录后如何使它可访问?

How can I make it accessible after login?

推荐答案

中间件是在App\Http\Controllers\Auth\AuthController.php类构造函数中设置的.

The middleware is set in the App\Http\Controllers\Auth\AuthController.php class constructor.

如果您使用Laravels样板身份验证控制器,则可能看起来像这样:

If your using Laravels boilerplate authentication controller, it will probably look something like this:

class AuthController extends Controller 
{

    ...

    public function __construct()
    {
        $this->middleware('guest', ['except' => 'getLogout']);
    }

    ...

}

您可以完全删除$this->middleware()行,以防止将中间件应用于您的所有登录和注册路由.

You could remove the $this->middleware() line entirely to prevent the middleware being applied to all your login and register routes.

或者,您可以将任何路由例外添加到作为第二个参数传递的数组中,以防止将中间件仅应用于那些方法.

Alternatively you could add any route exceptions to the array passed as the second parameter to prevent the middleware being applied to just those methods.

$this->middleware('guest', ['except' => ['getLogout', 'getRegister', 'postRegister']]);

这篇关于Laravel 5 Auth登录后注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆