Reversing php artisan make:auth in Laravel
Running php artisan make:auth is a convenient shortcut for scaffolding a fresh project, but it is also an aggressive command. It creates a dedicated authentication controller, registers middleware, adds views, andâmost critically for database-driven applicationsâdefines the users table in your schema. If you realize later that you need a custom user structure or simply don't want the standard auth flow, removing this generated code isn't just about deleting files; it requires careful attention to Laravel's configuration lifecycle and migration state.
The most common pitfall arises from the assumption that deleting the generated files is sufficient. You might remove app/Http/Controllers/Auth/AuthenticatedSessionController.php, clear out the views in the resources/views folder, and delete the route definitions. However, simply wiping these files does not restore your database to a pre-authentication state. The users table, created by the scaffolding process, remains in your migration history. When you attempt to re-run php artisan make:auth, you will find that Laravel detects the existing table and skips its creation, or worse, attempts to alter it in ways that conflict with your custom requirements.
To truly remove the authentication setup, you must address three distinct layers: code, configuration, and data migration.
Cleaning Up Code and Configuration
First, strip out the generated controllers and views. Locate the AuthenticatedSessionController, RegisteredUserController, NewPasswordController, and any other auth-specific files in your app/Http/Controllers directory. Delete them entirely. Similarly, remove the corresponding route definitions from routes/web.php or routes/auth.php if you are using Laravel 11's modular routing structure.
Next, inspect your service provider. The make:auth command registers specific middleware and binds the auth facade to the user model. Open app/Providers/AuthServiceProvider.php (or AppServiceProvider.php in older versions) and remove any calls to AuthServiceProvider::mapUsersToRoles or similar registration logic that was injected by the scaffolding tool. If you added a migration for a users table that has default columns like email_verified_at, remember_token, etc., these are part of the generated schema and should be removed if you intend to build your own user model from scratch.
Handling the Database Migration
This is where many developers get stuck. Laravel's migrations are designed to be additive by default; they do not automatically rollback when you delete a file. The users table persists in your database regardless of whether the controller exists. If you plan to re-initialize authentication later, you have two options:
- Keep the Table: If your custom user schema is compatible with the generated one (i.e., you only add columns), you can keep the migration and simply delete the scaffolding files. This allows you to re-run
make:authsafely, as Laravel will see the table exists and won't try to recreate it. - Rollback the Migration: If you need a clean slate or a completely different user structure, you must manually remove the migration that creates the
userstable. Open yourdatabase/migrations/*_create_users_table.phpfile and delete it from your filesystem. Then, runphp artisan migrate:fresh --seedorphp artisan migrate:rollback --step=1to drop the table from the database. Warning: Do not usemigrate:freshunless you are okay with deleting all existing data in your project, as it drops and recreates all migrations.
Re-initializing Safely
Once the files and the migration file are gone, running php artisan make:auth again will behave differently. It will attempt to create the users table. If you deleted the migration file but kept the database schema (which is rare), you might encounter a "table already exists" error. In that case, ensure the migration file is gone and the table is dropped before running the command.
If your goal is simply to stop using the standard auth flow without deleting the users table entirely, no further action is needed on the database side. You just leave the table alone and delete the controllers. The next time you run make:auth, Laravel will detect the existing table and skip the creation step, effectively re-initializing the code layers without altering your data schema.
Trade-offs to Consider
Removing auth scaffolding is often done to build a custom login system or to integrate with an external identity provider like OAuth. In these cases, keeping the users table might be beneficial if you want to merge external user data into the existing structure later. Conversely, if you are starting a new feature branch and want to avoid conflicts with standard auth files, rolling back the migration provides a cleaner start at the cost of losing existing user records.
Always verify your .env file as well. The make:auth command may have set default values for MAIL_MAILER, APP_NAME, or other variables specific to the scaffolding examples. Reviewing these ensures you aren't accidentally locking yourself into a configuration that assumes the presence of auth-specific services.