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
I found this to be the easiest solution in laravel 5.6! It redirects anyone who tries to go to yoursite.com/register to yoursite.com
routes/web.php
// redirect from register page to home page
Route::get('/register', function () {
return redirect('/');
});
add
use \Redirect;
at the top of the file
Overwriting the getRegister and postRegister is tricky - if you are using git there is a high possibility that .gitignore
is set to ignore framework files which will lead to the outcome that registration will still be possible in your production environment (if laravel is installed via composer for example)
Another possibility is using routes.php and adding this line:
Route::any('/auth/register','HomeController@index');
This way the framework files are left alone and any request will still be redirected away from the Frameworks register module.
In Laravel 5.5 is very simple, if you are using CRUD route system.
Go to app/http/controllers/RegisterController
there is namespace: Illuminate\Foundation\Auth\RegistersUser
You need to go to the RegistersUser: Illuminate\Foundation\Auth\RegistersUser
There is the method call showRegistrationForm
change this: return view('auth.login');
for this: return redirect()->route('auth.login');
and remove from you blade page route call register. It may look like that:
<li role="presentation">
<a class="nav-link" href="{{ route('register') }}">Register</a>
</li>
In laravel 5.3, you should override the default showRegistrationForm()
by including the code below into the RegisterController.php
file in app\Http\Controllers\Auth
/**
* Show the application registration form.
*
* @return \Illuminate\Http\Response
*/
public function showRegistrationForm()
{
//return view('auth.register');
abort(404); //this will throw a page not found exception
}
since you don't want to allow registration, it's better to just throw 404 error
so the intruder knows he is lost. And when you are ready for registraation in your app, uncomment //return view('auth.register');
then comment abort(404);
\\\\\\\\\\\\\\\\\\\\JUST AN FYI///////////////////////////////
If you need to use multiple authentication like create auth for users, members, students, admin, etc. then i advise you checkout this hesto/multi-auth its an awesome package for unlimited auths in L5 apps.
You can read more abouth the Auth methodology and its associated file in this writeup.
LAravel 5.6
Auth::routes([
'register' => false, // Registration Routes...
'reset' => false, // Password Reset Routes...
'verify' => false, // Email Verification Routes...
]);