🔐 Laravel Authentication with Laravel/UI and Bootstrap – Step-by-Step Setup

Looking to create a Laravel project with built-in authentication using Laravel/UI and Bootstrap? Whether you're a beginner or just need a refresher, this guide will walk you through the process from scratch. Let’s get started! 🚀


📦 Step 1: Install Laravel Globally

First, make sure you have Laravel installed globally. Open your terminal and run:

composer global require laravel/installer

✅ This command installs the Laravel CLI, allowing you to use the laravel command anywhere on your system.


🛠️ Step 2: Create a New Laravel Project

Now, navigate to the directory where you want your project, and create a new Laravel app:

laravel new myproject

📝 Replace myproject with the name you want for your application.


📁 Step 3: Navigate to Your Project & Install Laravel/UI

After the project is created, go into the directory:

cd myproject

Then install the Laravel/UI package:

composer require laravel/ui

📌 Laravel/UI is a separate package that provides authentication scaffolding for Laravel using Bootstrap, Vue, or React.


🎨 Step 4: Generate Bootstrap Authentication Scaffolding

Run the following command to generate Bootstrap-based auth UI:

php artisan ui bootstrap --auth

This command does the following:

  • Adds Bootstrap CSS/JS dependencies
  • Generates auth views (login, register, reset, etc.)
  • Adds routing and controller scaffolding for authentication


📦 Step 5: Install Frontend Dependencies

After generating the UI scaffolding, install the frontend dependencies and compile assets:

npm install
npm run dev

💡 You can use npm run build for production.

Make sure you have Node.js and npm installed. You can check with:

node -v
npm -v

🚀 Step 6: Start Laravel Development Server

You can now serve your Laravel app locally:

php artisan serve

Visit http://localhost:8000 in your browser.

You’ll see the default Laravel landing page, and you can now register or log in using the authentication system you've just built.


🧩 What's Inside?

When you run php artisan ui bootstrap --auth, Laravel generates:

  •     Authentication views:
    • resources/views/auth/*
    • resources/views/layouts/app.blade.php
  • Auth controllers:
    • app/Http/Controllers/Auth/LoginController.php
    • app/Http/Controllers/Auth/RegisterController.php
    • app/Http/Controllers/Auth/ForgotPasswordController.php etc.
  • Routes:
    • Defined in routes/web.php via Auth::routes();

🎯 Customize Your Auth

Want to make it yours? You can:

  • Edit the Blade templates in resources/views/auth
  • Customize logic in controllers under app/Http/Controllers/Auth
  • Use middlewares like auth, guest, or verified

For example, to protect a route:

Route::get('/dashboard', function () {
return view('dashboard');
})->middleware('auth');

📚 Useful Laravel Authentication Commands

Command Description
php artisan ui bootstrap --auth Bootstrap with auth scaffolding
php artisan route:list Show all routes (includes auth routes)
php artisan make:controller Create custom controllers
npm run watch Auto-recompile assets on save

🧠 Need More Control?

If you're building a SPA or API-first application, consider:

  • Laravel Breeze – lightweight and modern
  • Laravel Jetstream – robust with teams, 2FA, API tokens
  • Laravel Fortify – backend-only auth for SPAs


🔗 Official Documentation

For advanced usage, visit the official docs:


✅ Conclusion

You now have a fully functional Laravel project with authentication powered by Laravel/UI and Bootstrap. This setup is great for traditional server-rendered apps and is a good starting point for customization.

Happy coding with Laravel! 🔥

Post a Comment

Previous Post Next Post

Contact Form