


How do I use Laravel's built-in authentication scaffolding? (php artisan ui bootstrap/vue/react --auth)
Jun 25, 2025 pm 05:20 PMTo set up Laravel’s built-in authentication scaffolding, ensure you are using a compatible version such as Laravel 8 or earlier, then install the UI package via Composer if necessary. Next, generate the auth views with Bootstrap, Vue, or React using the php artisan ui command, followed by compiling front-end assets with npm. Finally, test the authentication flow by visiting /register or /login and confirm protected routes redirect correctly—note that for Laravel 9 and above, Laravel Breeze or Jetstream is required instead of the legacy UI package.
Laravel comes with a built-in authentication scaffolding system that makes it easy to get started with user registration, login, password reset, and more. If you're setting up a new Laravel project and want a quick, functional auth system without building everything from scratch, this is the way to go.
1. Make Sure You’re Using a Compatible Laravel Version
Before jumping into the commands, check your Laravel version. The php artisan ui
command for generating authentication views was available in Laravel 6 through 8. It has since been moved out of core Laravel and into separate packages (like Laravel Breeze or Jetstream in later versions).
If you're using Laravel 8 or earlier, you can proceed with the built-in UI generator. For newer versions, consider installing Laravel Breeze via Composer instead.
2. Install UI Package (if needed)
In some cases, especially if you created your project with the --minimal
flag or are using a fresh install, you may need to install the Laravel UI package first:
composer require laravel/ui
Once installed, you’ll have access to the php artisan ui
command.
3. Generate Auth Scaffolding with Bootstrap, Vue, or React
Now you can generate the authentication views and related assets using one of these commands:
Bootstrap:
php artisan ui bootstrap --auth
Vue:
php artisan ui vue --auth
React:
php artisan ui react --auth
This will:
- Create all necessary auth-related views in
resources/views/auth
- Set up layouts and home controllers
- Add a
HomeController
for authenticated dashboard - Include navigation links in the default layout (
resources/views/layouts/app.blade.php
) - Generate front-end assets like JS/CSS files depending on your chosen framework
Note: This doesn’t run database migrations or set up models — those are already included by default in a fresh Laravel app.
4. Compile Assets After Generating UI
After running the UI command, don't forget to install and compile your front-end assets:
npm install npm run dev
Or, if you're using Laravel Mix:
npm run development
Make sure your package.json
includes the required dependencies. If not, you might need to run:
npm install bootstrap jquery popper.js axios --save-dev
For Vue or React, also make sure their respective packages are installed.
5. Test Your Authentication Flow
Once everything compiles:
- Visit
/register
or/login
in your browser - Try registering a new user and logging in
- Check that protected routes redirect properly when not logged in
The default setup uses Laravel’s built-in authentication middleware and redirects to /home
after login, which you can customize in the LoginController
and RegisterController
.
A Few Things to Watch Out For
- The generated views assume you're using Bootstrap, Vue, or React, so make sure your front-end stack matches.
- If you're using Laravel 9 or above, you'll need to use Laravel Breeze or Jetstream instead of the old UI package.
- Don’t forget to run
npm run dev
after every time you regenerate the UI, or changes won’t show up in the browser.
That’s basically how to use Laravel's built-in authentication scaffolding. It's a fast way to get started, and while it's no longer part of the core in newer versions, it still works great if you're on an older release or bring in the right packages.
The above is the detailed content of How do I use Laravel's built-in authentication scaffolding? (php artisan ui bootstrap/vue/react --auth). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Efficient methods for testing Laravel API interfaces include: 1) using Laravel's own testing framework and third-party tools such as Postman or Insomnia; 2) writing unit tests, functional tests and integration tests; 3) emulating a real request environment and managing database status. Through these steps, the stability and functional integrity of the API can be ensured.

Custom Laravel user authentication logic can be implemented through the following steps: 1. Add additional verification conditions when logging in, such as mailbox verification. 2. Create a custom Guard class and expand the authentication process. Custom authentication logic requires a deep understanding of Laravel's authentication system and pay attention to security, performance and maintenance.

The steps to create a package in Laravel include: 1) Understanding the advantages of packages, such as modularity and reuse; 2) following Laravel naming and structural specifications; 3) creating a service provider using artisan command; 4) publishing configuration files correctly; 5) managing version control and publishing to Packagist; 6) performing rigorous testing; 7) writing detailed documentation; 8) ensuring compatibility with different Laravel versions.

Integrating social media login in the Laravel framework can be achieved by using the LaravelSocialite package. 1. Install the Socialite package: use composerrequirelaravel/socialite. 2. Configure the service provider and alias: add relevant configuration in config/app.php. 3. Set API credentials: Configure social media API credentials in .env and config/services.php. 4. Write controller method: Add redirection and callback methods to handle social media login process. 5. Handle FAQs: Ensure user uniqueness, data synchronization, security and error handling. 6. Optimization practice:

TosecurelyhandleauthenticationandauthorizationinPHP,followthesesteps:1.Alwayshashpasswordswithpassword_hash()andverifyusingpassword_verify(),usepreparedstatementstopreventSQLinjection,andstoreuserdatain$_SESSIONafterlogin.2.Implementrole-basedaccessc

Implementing password reset function in Laravel requires the following steps: 1. Configure the email service and set relevant parameters in the .env file; 2. Define password reset routes in routes/web.php; 3. Customize email templates; 4. Pay attention to email sending problems and the validity period of tokens, and adjust the configuration if necessary; 5. Consider security to prevent brute-force attacks; 6. After the password reset is successful, force the user to log out of other devices.

Common security threats in Laravel applications include SQL injection, cross-site scripting attacks (XSS), cross-site request forgery (CSRF), and file upload vulnerabilities. Protection measures include: 1. Use EloquentORM and QueryBuilder for parameterized queries to avoid SQL injection. 2. Verify and filter user input to ensure the security of output and prevent XSS attacks. 3. Set CSRF tokens in forms and AJAX requests to protect the application from CSRF attacks. 4. Strictly verify and process file uploads to ensure file security. 5. Regular code audits and security tests are carried out to discover and fix potential security vulnerabilities.

Middleware is a filtering mechanism in Laravel that is used to intercept and process HTTP requests. Use steps: 1. Create middleware: Use the command "phpartisanmake:middlewareCheckRole". 2. Define processing logic: Write specific logic in the generated file. 3. Register middleware: Add middleware in Kernel.php. 4. Use middleware: Apply middleware in routing definition.
