triquang / laravel-auth-scaffold
Scaffold API & Web authentication for any Laravel model โ supports multi-auth & modular structure.
Requires
- php: ^8.0
- illuminate/support: ^11.0 || ^12.0
README
๐ 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
- Check if model extends
๐งฉ 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
- GitHub: github.com/ntquangkk
- Email: ntquangkk@gmail.com