How to disable registration new users in Laravel

后端 未结 27 2786
鱼传尺愫
鱼传尺愫 2020-12-07 10:34

I\'m using Laravel (v5).

I need one user and I\'ve already registered that. Now I want to disable registration for new users. Of course, I need the login form to wor

相关标签:
27条回答
  • 2020-12-07 11:30

    For Laravel 5.3 and 5.4, here is the proper way to do it:

    You have to change:

    public function __construct()
        {
            $this->middleware('guest');
        }
    

    to

    public function __construct()
        {
            $this->middleware('auth');
        }
    

    in app/Http/Controller/Auth/RegisterController.php

    0 讨论(0)
  • 2020-12-07 11:31

    All I did was replace register blade code with login blade code. That way register still goes to login.

    resources/views/auth/register.blade.php is replaced with resources/views/auth/login.blade.php

    0 讨论(0)
  • 2020-12-07 11:32

    For Laravel 5.6+, paste the below methods in app\Http\Controller\Auth\RegisterController

    /*
    * Disabling registeration.
    *
    */
    public function register() 
    {
        return redirect('/');
    }
    
    /*
    * Disabling registeration.
    *
    */
    public function showRegistrationForm() 
    {
        return redirect('/');
    }
    

    Now you're overriding those methods in RegistersUser trait, whenever you change your mind remove these methods. You may also comment the register links in welcome.blade.php and login.blade.php views.

    0 讨论(0)
提交回复
热议问题