Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to disable user registration in Laravel 5

    • 0
    • 22
    • 3
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.09k
    Comment on it

    Laravel 5 provides built-in user registration and login functionality which allow developer to easily integrate both functionality in their application. But some times laravel developer wants to disable the user registration or restrict user for registration into the system.

    For Example
    If you are trying to make single user admin panel (which has only one user) in Laravel 5. if you want to disable user registration for new users. You can easily disable user registration process by overriding getRegister() and postRegister() methods in AuthController.php Trace this path "app/Http/Controllers/Auth" to view AuthController.php file.

    <?php namespace App\Http\Controllers\Auth;
    
    use App\Http\Controllers\Controller;
    use Illuminate\Contracts\Auth\Guard;
    use Illuminate\Contracts\Auth\Registrar;
    use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
    
    class AuthController extends Controller {
    
        /*
        |--------------------------------------------------------------------------
        | Registration & Login Controller
        |--------------------------------------------------------------------------
        |
        | This controller handles the registration of new users, as well as the
        | authentication of existing users. By default, this controller uses
        | a simple trait to add these behaviors. Why don't you explore it?
        |
        */
    
        use AuthenticatesAndRegistersUsers;
    
        /**
         * Create a new authentication controller instance.
         *
         * @param  \Illuminate\Contracts\Auth\Guard  $auth
         * @param  \Illuminate\Contracts\Auth\Registrar  $registrar
         * @return void
         */
        public function __construct(Guard $auth, Registrar $registrar)
        {
            $this--->auth = $auth;
            $this->registrar = $registrar;
    
            $this->middleware('guest', ['except' => 'getLogout']);
        }
    
        public function getRegister()
        {
            return redirect('/search');
        }
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: