Laravel 10 Application with Bootstrap Auth Scaffolding

Laravel 10 Application with Bootstrap Auth Scaffolding

Laravel, a widely used web development framework written in PHP, is renowned for its elegant syntax, extensive feature set, and a thriving community of developers. The most recent iteration, Laravel 10, introduces a range of new features and enhancements, including Bootstrap Auth scaffolding—a notable addition that streamlines the setup of basic authentication systems in Laravel applications, leveraging the Bootstrap CSS framework.

Tutorial: Setting Up Laravel 10 Application with Bootstrap Auth Scaffolding

To create a Laravel 10 application with Bootstrap Auth scaffolding, follow these comprehensive steps:

Step 1: Create a New Laravel 10 Project

Start by initiating a new Laravel project. You can do this using Composer:

composer create-project laravel/laravel laravel-auth-bootstrap

Step 2: Install Laravel UI

Next, incorporate the Laravel UI package to enable user interface components within your Laravel application:

composer require laravel/ui

Step 3: Install Bootstrap Auth Scaffolding

Now, introduce the Bootstrap Auth scaffolding using Artisan commands:

php artisan ui bootstrap --auth

Step 4: Install and Compile NPM Packages

Install the required Node.js packages and compile assets using NPM:

npm install && npm run dev

Step 5: Implement MustVerifyEmail Contract

In your User model, implement the MustVerifyEmail contract. This step is essential for email verification:

class User extends Authenticatable implements MustVerifyEmail
{
    // ...
}

Step 6: Secure Auth Routes with Verification Middleware

Protect your authentication routes with the email verification middleware in the web.php route file:

Route::group(['middleware' => ['auth', 'verified']], function() {
    Route::get('/', [HomeController::class, 'index'])->name('home');
});

Step 7: Update HomeController Middleware

In the HomeController.php file, ensure that the Verified middleware is used to verify email:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class HomeController extends Controller
{
    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $user = Auth::user();

        return view('home', [
            'user' => $user,
        ]);
    }
}

Step 8: Configure Database and SMTP Credentials

Update the .env file with your specific database and SMTP (email) credentials.

Step 9: Migrate Tables to Database

Apply the necessary migrations to create tables in the database:

php artisan migrate

Step 10: Run Laravel Development Server

Initiate the Laravel development server to make your application accessible:

php artisan serve

With these steps completed, your Laravel 10 application with Bootstrap Auth scaffolding is ready for use. You can access it in your web browser, where you'll be able to create a new account or log in with existing credentials.

Conclusion

Bootstrap Auth scaffolding in Laravel 10 simplifies the establishment of fundamental authentication systems. It leverages the Bootstrap CSS framework to produce responsive and user-friendly authentication interfaces. After installing Bootstrap Auth scaffolding, you can further tailor the authentication screens to harmonize with your application's aesthetics. Additionally, you can enhance authentication functionality by integrating additional Laravel packages for features like social media login or two-factor authentication.


  • Date: