How to disable registration new users in Laravel

后端 未结 27 2917
鱼传尺愫
鱼传尺愫 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:14

    Method 1 for version 5.3

    In laravel 5.3 don't have AuthController. to disable register route you should change in constructor of RegisterController like this:

    You can change form:

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

    to:

    use Illuminate\Support\Facades\Redirect;
    
    public function __construct()
    {
    
        Redirect::to('/')->send();
    
    }
    

    Note: for use Redirect don't forget to user Redirect; So user access to https://host_name/register it's redirect to "/".

    Method 2 for version 5.3

    When we use php artisan make:auth it's added Auth::route(); automatically. Please Override Route in /routes/web.php. You can change it's like this: * you need to comment this line: Auth::routes();

        

    Thanks! I hope it's can solve your problems.

提交回复
热议问题