How to Implement Laravel UI Auth Scaffolding in Laravel 9: A Complete Guide
To add authentication scaffolding to a Laravel 9 project, install the laravel/ui package, generate the scaffolding with the --auth flag, compile the frontend assets, and run your database migrations.
Laravel 9 removed the classic Auth::routes() functionality from the core framework to keep the base installation lean. To generate the traditional laravel ui auth scaffolding—including login, registration, and password reset views—you must explicitly install the optional laravel/ui package, which registers the necessary service provider and router macros.
Why Laravel 9 Requires the UI Package for Authentication
The Auth Facade Guard Clause
When you call Auth::routes() in a fresh Laravel 9 installation, the framework throws a RuntimeException with the message:
"In order to use the Auth::routes() method, please install the laravel/ui package."
This guard clause lives in src/Illuminate/Support/Facades/Auth.php at lines 91-98. The method checks whether the UiServiceProvider is loaded; if not, it halts execution immediately. The framework’s integration tests confirm this behavior in tests/Integration/Support/AuthFacadeTest.php at lines 11-18, ensuring the exception fires when the UI package is absent.
What the UI Package Provides
Installing laravel/ui registers the UiServiceProvider, which bootstraps the authentication layer through a router macro named auth. This macro performs three critical tasks:
- Registers standard routes for
login,register,password/reset, andpassword/email. - Binds controller classes such as
LoginControllerandRegisterControllerthat handle the authentication logic. - Publishes Blade view scaffolding for the login, registration, and password reset interfaces.
Once the package is installed, calling Auth::routes() successfully delegates to this macro, wiring up the complete authentication flow.
Step-by-Step Implementation Guide
1. Create a Fresh Laravel 9 Project
Start by creating a new project using Composer:
composer create-project laravel/laravel example-app
cd example-app
2. Install the Laravel UI Package
Require the laravel/ui package. Version ^3.2 is the first release that supports Laravel 9:
composer require laravel/ui "^3.2"
3. Generate the Authentication Scaffolding
Run the ui artisan command with the --auth flag. You can choose Bootstrap, Vue, or React as your frontend preset:
# For Bootstrap scaffolding
php artisan ui bootstrap --auth
# For Vue scaffolding
php artisan ui vue --auth
# For React scaffolding
php artisan ui react --auth
This command generates the authentication controllers, routes, and Blade view files.
4. Compile Frontend Assets
Install the Node dependencies and compile the assets:
npm install
npm run dev
For production environments, use npm run build instead of npm run dev.
5. Run Database Migrations
The scaffolding includes migrations for the users table and password resets. Run the migrations to create these tables:
php artisan migrate
6. Verify the Installation
Start the development server and test the authentication endpoints:
php artisan serve
Visit http://localhost:8000/login and http://localhost:8000/register to confirm the views load correctly and the authentication system is functional.
Summary
- Laravel 9 removed
Auth::routes()from the core framework; you must install thelaravel/uipackage to restore this functionality. - The
Authfacade insrc/Illuminate/Support/Facades/Auth.phpthrows aRuntimeExceptionif you callroutes()without the UI package installed. - The
laravel/uipackage registersUiServiceProvider, which defines a router macro that binds authentication controllers and publishes Blade views. - To implement the scaffolding, require
laravel/uiversion^3.2, runphp artisan ui bootstrap --auth(orvue/react), compile assets with npm, and run migrations.
Frequently Asked Questions
Why was Auth::routes() removed from Laravel 9 core?
The Laravel team removed the classic authentication scaffolding from the core framework to reduce the default installation size and to encourage modern frontend solutions like Laravel Breeze or Jetstream. The laravel/ui package remains available as an optional legacy solution for developers who prefer the Bootstrap, Vue, or React scaffolding.
Can I use Laravel UI with Vue or React instead of Bootstrap?
Yes. The laravel/ui package supports three frontend presets. You can generate the authentication scaffolding with Vue by running php artisan ui vue --auth, or with React using php artisan ui react --auth. Each preset includes the corresponding JavaScript components and build configuration.
What should I do if I get the "please install the laravel/ui package" error?
If you encounter the RuntimeException stating "In order to use the Auth::routes() method, please install the laravel/ui package", you need to run composer require laravel/ui in your project root. After installation, the UiServiceProvider will register the necessary router macro, and Auth::routes() will function correctly.
Is Laravel UI the only way to add authentication to Laravel 9?
No. While laravel/ui provides the classic scaffolding, Laravel 9 also supports Laravel Breeze (a minimal, Tailwind CSS-based implementation) and Laravel Jetstream (a more robust application starter kit with Livewire or Inertia). These are the officially recommended solutions for new projects, while laravel/ui is maintained primarily for legacy compatibility.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →