Why Auth::routes() Fails in Laravel 9 Without laravel/ui
Upgrading a legacy project to Laravel 9 often reveals friction points that were glossed over in earlier versions. One of the most common stumbling blocks is the error encountered when running php artisan serve or executing migrations:
In Auth.php line 60: To use the Auth::routes() method, please install the laravel/ui package.
This message appears immediately if you attempt to call Auth::routes() in your web.php or api.php route files without having the laravel/ui dependency explicitly installed. The error isn't a mystery; it is a direct consequence of how Laravel 9 refactored its authentication scaffolding and changed the default expectations for new applications.
The Shift from Built-in to Package-Based Auth
In previous iterations of the framework, Laravel provided basic authentication routes out of the box as part of the core installation. You could simply call Auth::routes() and get a set of standard login, register, and logout endpoints without needing any additional packages. This approach was convenient for rapid prototyping but lacked the robustness of a dedicated scaffolding package.
Laravel 9 made a deliberate architectural decision to remove these basic authentication routes from the core framework. The logic behind this move is that Auth::routes() relies on specific view paths, middleware configurations, and session handling that were previously hardcoded or loosely coupled within the core. By removing them, the framework encourages developers to use the dedicated laravel/ui package, which provides a complete, tested, and secure authentication scaffolding system.
When you call Auth::routes() without the package installed, Laravel cannot locate the necessary view files (like auth/login) or the specific controller logic required to handle the session redirects. Consequently, it throws this explicit error at runtime rather than silently failing or throwing a generic 500 error.
Installing and Configuring the Package
To resolve this, you must install the laravel/ui package via Composer. Run the following command in your project directory:
composer require laravel/ui
Once installed, you need to generate the scaffolding files that define the authentication routes and views. Execute the artisan command below:
php artisan ui vue --auth
# Or use blade if you prefer Blade templates: php artisan ui blade --auth
This command creates the necessary controllers, views, and route definitions in your resources/views directory. After generating the scaffolding, ensure that the AuthServiceProvider is properly registered to bind the authentication routes. In modern Laravel versions using service providers, this often happens automatically, but verifying that the ViewServiceProvider is loaded is crucial if you are seeing "view not found" errors immediately after installation.
Migrating Existing Routes
If your legacy application relies on custom route definitions in web.php, you will need to adjust them. The old pattern looks like this:
// web.php (Before)
Route::get('/login', 'AuthController@login');
Route::post('/login', 'AuthController@postLogin');
Route::get('/logout', 'AuthController@logout');
With Laravel 9 and laravel/ui, the recommended approach is to let the package handle these routes automatically. You should remove manual route definitions for login, register, and logout from your web.php file. The laravel/ui package registers its own routes during bootstrapping, typically mapping /login, /register, and /forgot-password to the correct controllers found in app/Http/Controllers/Auth.
Trade-offs and Best Practices
The primary trade-off here is the loss of flexibility in core authentication logic versus the gain in security and consistency. The laravel/ui package enforces a standard structure that aligns with Laravel's security best practices, ensuring CSRF tokens are handled correctly and session lifecycles are managed properly.
A common pitfall during upgrades is assuming that custom authentication controllers can coexist seamlessly with the new package without configuration conflicts. If you have heavily customized the login logic in your legacy app, simply installing laravel/ui might override your existing behavior. In such cases, consider extending the scaffolding or using the laravel/breeze package as an alternative if you need a lighter-weight solution that still adheres to Laravel 9's architecture.
By understanding this architectural shift, you can upgrade your projects smoothly without being blindsided by runtime errors related to missing dependencies or undefined views.
