1

i want to disable normal registeration method in Laravel, because i want just administrator the one that can register and manage/edit user.
But i doesnt know how to do it and start from where.

Thanks

Edit :
I'am not just asking how to disable default register, but also how to make Admin manually regist user in Control Panel.

vl14b
  • 85
  • 2
  • 14
  • Possible duplicate of [Laravel 5.4 Disable Register Route](https://stackoverflow.com/questions/42695917/laravel-5-4-disable-register-route) – dparoli May 23 '17 at 06:48
  • @dparoli No, im asking how to make register manually, not just disable default register route. – vl14b May 23 '17 at 06:56

3 Answers3

1

Currently, the only way to manage what you want is to remove the

Auth::routes();

From the routes/web.php and add each routes one by one.

You have all the routes Auth::routes() adds here :

vendor/laravel/framework/src/Illuminate/Routing/Router.php

in the auth method.

Just copy paste them all in your routes/web.php and remove the one you don't want (the GET and POST request on /register).

As for registering the users in an admin panel, there are several ways you could do it. Here is one :

You have a bool on your user model which I would call is_admin.

You create a middleware isAdminMiddleware where you check if the user has the is_admin property. If he has it, you can go further, otherwise just go back to the previous page or return a 403.

In a UsersController for example, create a GET method, which returns the view containing the form for creating a new user.

In the same controller, create a POST method, which adds the new user to the database and makes proper validation.

Don't forget to protect both routes with isAdminMiddleware so that users can't go to that page.

Alex
  • 1,368
  • 10
  • 20
  • Thanks, your explanation is so good, i can understand almost of it. But i have one more question, " So i just need to make a new controller and crud for regist user?". Thanks. – vl14b May 23 '17 at 06:58
  • It depends the way you want to structure your Controllers, it's a way yes and works fine, but some people (me included) prefer Single Action Controllers (basically, you split each method into it's own controller). I guess it's more of a personal choice – Alex May 23 '17 at 07:43
1

If you really want to keep Auth::routes() scaffolding but disable registering from outside the admin's "control panel", this is the simplest way to do it:

Simply override methods from RegistersUsers trait in your app/Http/Controllers/Auth/RegisterController.php class.

public function showRegistrationForm() {
    abort(403, 'Unauthorized action.');
}

public function register() {
    abort(403, 'Unauthorized action.');
}

Second simple option is to change a middleware in __construct() method of your RegisterController.php:

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

to

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

or to some custom middleware, like:

public function __construct() {
    $this->middleware('admin');
}
lbartolic
  • 1,165
  • 2
  • 12
  • 24
0

When you run php artisan make:auth to scaffold Laravel's authentication feature, a lot of things happen.

In routes/web.php, you will need to remove this line

Auth::routes();

This will make routes such as /login and /register inaccessible.

You can also clean up the views that you won't need in resources/views/auth

Finally, you would need to write your own code from your secure administration panel to register a user that will re-use the traits that Laravel already provides.

Mozammil
  • 8,520
  • 15
  • 29
  • 1
    Not really, no. You can take inspiration from `app/Http/Controllers/Auth/RegisterController.php` – Mozammil May 23 '17 at 05:47
  • Ok, so i just need to remove auth::routes(); then i need to make a new routes for my login ? and then i need to make a new controller for register ? sorry, can u eli5 or step by step explanation for me? i doesnt get it at all. – vl14b May 23 '17 at 05:59