Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

naneri's avatar

How to disable registration in Spark Application?

I want to disable registration in my Spark App, so that the user that I define as admin in my seeds will add other users manually. How can I achieve that?

0 likes
9 replies
zanematthew's avatar

Does this help?

$router->get('/register', function(){
        dd('no'); // have this redirect to a page of your choice.
    });
naneri's avatar

I don't think that editing the vendor files is a good idea, because next update will just wipe it out... Or am I wrong?

1 like
EventFellows's avatar

I guess you could just use the Controller/Auth/AuthController.php to abort the user creation process if a user does not come via an invitation and redirect them to a 'Sorry, access is only possible if you have been invited'-page.

haydenp's avatar

I too would love to know the best way to remove certain Spark routes without having to comment them out in vendor routes.php file?

// Registration...
$router->get('/register', 'Auth\RegisterController@showRegistrationForm');
$router->post('/register', 'Auth\RegisterController@register');

At the moment I'm just commenting the routes above out, but there must be a better way without having to touch the vendor files?

If I add a route in app/Http/routes.php ...

Route::get('/register', function () {
    dd('Show 404 page!!!');
});

... the default Spark register form is shown. If I comment out the Registration routes in vendor/laravel/spark/source/Http/routes.php then (and only then) does my 'Show 404 page!!!' route take effect!

trea's avatar

One thing that occurred to me as I looked to do the same. I believe the Laravel router is first-in-first-out, meaning that if your route is defined in the router after the original GET /register route, the original will be overridden.

So if your route is registered after the Spark routes are, you can override routes that way. Out of the box in config/app.php I found that the Spark provider App\Providers\SparkServiceProvider::class is loaded before App\Providers\RouteServiceProvider::class. I moved the RouteServiceProvider class further down so that it comes after the SparkServiceProvider.

It should be noted that I haven't tested this thoroughly, but if this proves to be an issue I will update this thread.

pryley's avatar

Just replace the register route by adding it to your /app/routes/web.php file like so:

// Disable Registration...
Route::get( '/register', function() {
    return redirect()->intended( '/' );
});
1 like
barkingsand22's avatar

Okay, so that worked for me... placing the RouteServiceProvider::class after the SparkServiceProider::class in the config/app.php file...

I can now trap for both the '/login', and '/register' routes in the web.php file.

Thanks for the help on the thread!

bufferoverflow's avatar

A bit late, but for people reading this now. I think it would be better to replace both get and post routes:

Route::match(['get', 'post'],  '/register', function() {
    return redirect()->intended( '/' );
});

If you leave the post route open it's possible to create an account and access auth routes.

UncleWu's avatar

Hi,

another option besides redirecting as mentioned in previous answers is to throw a 404 page.

Route::match(['get', 'post'],  '/register', function() {
    return abort(404);
});

Please or to participate in this conversation.