triquang/laravel-auth-scaffold

Scaffold API & Web authentication for any Laravel model โ€” supports multi-auth & modular structure.

1.0.0 2025-08-01 16:30 UTC

This package is auto-updated.

Last update: 2025-08-01 16:36:39 UTC


README

Latest Version on Packagist Total Downloads License

๐Ÿš€ Quickly scaffold full Laravel authentication for any Eloquent model, supporting both API and Web UI โ€” monolith or modular apps.

This package accelerates authentication setup for custom models like Admin, Client, Vendor, etc., and works seamlessly with both standard Laravel and modular Laravel architectures (e.g., nwidart/laravel-modules).

โœจ Features

  • โœ… Supports any Eloquent model (User, Admin, Client, etc.)
  • โœ… Scaffold for both API routes/controllers/services and Web (views/forms)
  • โœ… Works with modules โ€” fully compatible with nwidart/laravel-modules
  • โœ… Multi-auth ready โ€” configure multiple guards & providers automatically
  • โœ… Generates:
    • Auth-ready Model (or updates existing one)
    • Migrations (with OTP, password reset)
    • Auth controllers (API + optional Web)
    • Requests, Services, Routes, Views (if --web)
    • Auth config updates (guards, providers, passwords)
  • โœ… One single command does it all

API functions

  • Register
  • Login
  • Logout
  • Forgot Password
  • Reset Password
  • Verify OTP

WEB functions

  • Includes all API functions above, plus:
    • Show register view
    • Show login view
    • Show Forgot Password view
    • Show Reset Password view
    • Show Verify OTP view

๐Ÿ“ฆ Installation

composer require triquang/laravel-auth-scaffold --dev

Optional: Publish Stubs

php artisan vendor:publish --provider="TriQuang\\LaravelAuthScaffold\\LaravelAuthScaffoldServiceProvider" --tag=auth-scaffold-stubs

This will publish stubs to:

/stubs/vendor/triquang/laravel-auth-scaffold/

๐Ÿš€ Usage

php artisan make:auth-scaffold --model=Admin

Options

Option Description
--model (Required) Name of the model to generate authentication for. Defaults to User.
--module (Optional) Generate files inside Modules/{ModuleName}.
--web (Optional) Include web views and web routes.

Examples

1. Generate basic API auth for default User model

php artisan make:auth-scaffold

2. Generate API auth for Admin model

php artisan make:auth-scaffold --model=Admin

3. Generate full auth for Author model inside a module

php artisan make:auth-scaffold --model=Author --module=Blog

4. Generate web+API auth for Client model

php artisan make:auth-scaffold --model=Client --web

๐Ÿ“‚ File Structure Generated

Example with --model=Admin:

app/
โ”œโ”€โ”€ Http/
โ”‚   โ””โ”€โ”€ Controllers/
โ”‚       โ””โ”€โ”€ Auth/
โ”‚           โ”œโ”€โ”€ AdminApiAuthController.php
โ”‚           โ””โ”€โ”€ AdminWebAuthController.php  # If --web
โ”œโ”€โ”€ Models/
โ”‚   โ””โ”€โ”€ Admin.php
โ”œโ”€โ”€ Services/
โ”‚   โ””โ”€โ”€ AdminAuthService.php
โ”œโ”€โ”€ Requests/
โ”‚   โ”œโ”€โ”€ AdminLoginRequest.php
โ”‚   โ”œโ”€โ”€ AdminRegisterRequest.php
โ”‚   โ”œโ”€โ”€ AdminForgotPasswordRequest.php
โ”‚   โ””โ”€โ”€ AdminResetPasswordRequest.php
database/
โ””โ”€โ”€ migrations/
    โ”œโ”€โ”€ create_admins_table.php
    โ”œโ”€โ”€ create_admin_password_reset_tokens_table.php
    โ””โ”€โ”€ create_admin_otp_codes_table.php
routes/
โ”œโ”€โ”€ api.php          # Updated
โ””โ”€โ”€ web.php          # If --web
resources/
โ””โ”€โ”€ views/
    โ””โ”€โ”€ auth/
        โ”œโ”€โ”€ admin-login.blade.php
        โ”œโ”€โ”€ admin-register.blade.php
        โ”œโ”€โ”€ admin-forgot-password.blade.php
        โ”œโ”€โ”€ admin-reset-password.blade.php
        โ””โ”€โ”€ admin-verify-otp.blade.php
config/
โ””โ”€โ”€ auth.php         # Auto-updated for guards/providers/passwords

๐Ÿ›ก Authentication Compatibility Check

  • The command will:
    • Check if model extends Illuminate\Foundation\Auth\User
    • Check if model has required traits like HasApiTokens
    • Insert guidance comments if not

๐Ÿงฉ Customization

You can customize the stub files to suit your coding standards:

php artisan vendor:publish --tag=auth-scaffold-stubs

Edit stubs in:

stubs/vendor/triquang/laravel-auth-scaffold/

๐Ÿงญ Auto-Generated Code Markers

This package adds clear flags in generated code to help developers easily find and review them.

Example

    // AUTO-GEN: Placeholder
    public function up()
    {
        Schema::create('admins', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->timestamps();
        
			// AUTH-SCAFFOLD-MISSING-COLUMNS
			// Required authentication fields missing in 'admins' migration:
			// $table->string('email')->unique();
			// $table->string('password');
			// $table->string('otp')->nullable();
			// $table->timestamp('email_verified_at')->nullable();
			// $table->string('remember_token')->nullable();
			// AUTH-SCAFFOLD-MISSING-COLUMNS
        });
    }

Available Markers

  • // AUTO-GEN-4-AUTH
  • // AUTO-GEN: Placeholder
  • // AUTH-SCAFFOLD-MISSING-COLUMNS

You can quickly search these markers (Ctrl/Cmd+Shift+F) to locate auto-generated code and remove them after review.

โ“ Why use this package?

Compared to Laravel Breeze, Jetstream or Fortify:

  • โœ… Supports any number of auth models (not just User)
  • โœ… Works in both standard and modular architectures
  • โœ… Auth flow is fully generated and flexible for customizing
  • โœ… Designed for fast scaffolding with clean, extensible code

๐Ÿ’ก Example Use Cases

  • Build multi separate auths for User, Admin, Vendor... in one app
  • Use in modular apps like Modules/User, Modules/Admin
  • Rapid implementing for auth APIs
  • Auto-generate secure & clean Laravel auth structure

๐Ÿšซ Limitations

  • Does not include frontend assets like Vue/React.
  • For OTP/email verification, you need to configure mail/notification system.

โœ… Requirements

  • PHP >= 8.0
  • Laravel 11 / 12
  • Composer
  • Optional: Laravel Sanctum
  • Optional: nwidart/laravel-modules

๐Ÿ“„ License

MIT ยฉ Nguyแป…n Trรญ Quang

๐Ÿ™Œ Contributing

PRs are welcome! Feel free to improve functionality or report issues via GitHub Issues.

๐Ÿ“ฌ Contact