ebrahemalwish / laravel-multi-guard
A Laravel package to scaffold multiple authentication guards (web, JWT, Passport) with migrations, models, middleware, controllers, routes, seeders, and views.
Package info
github.com/ebrahem-eng/laravel-multi-guard
pkg:composer/ebrahemalwish/laravel-multi-guard
Requires
- php: ^8.1
- illuminate/console: ^10.0|^11.0|^12.0
- illuminate/filesystem: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
This package is not auto-updated.
Last update: 2026-05-07 13:52:13 UTC
README
A Laravel package that scaffolds multiple authentication guards in seconds — complete with migrations, models, middleware, controllers, routes, seeders, and a beautiful Aurora UI.
What does this package do?
Run one command and answer a few questions. The package will automatically generate every file needed for each authentication guard you define — whether it's a classic web session guard, a JWT API guard, or a Passport API guard.
No more copy-pasting boilerplate across admin, vendor, driver, customer, and however many other guard types your project needs.
Requirements
| Dependency | Version |
|---|---|
| PHP | ^8.1 |
| Laravel | ^10.0 | ^11.0 | ^12.0 |
| tymon/jwt-auth (optional, for JWT guards) | ^2.0 |
| laravel/passport (optional, for Passport guards) | ^12.0 |
Installation
composer require ebrahemalwish/laravel-multi-guard
Laravel's auto-discovery will register the service provider automatically.
Usage
Build guards
php artisan multi-guard:build
The command will ask:
- How many guards do you want? — enter a number (anything else is rejected with an error).
- Guard name — e.g.
admin,vendor,customer. - Guard type —
weborapi. - (API only) API driver —
jwtorpassport.
Repeat steps 2–4 for each guard, then sit back.
Remove guards
php artisan multi-guard:remove
Enter comma-separated guard names, or type all to remove every guard that was generated.
You will be asked to confirm before any files are deleted.
What gets generated per guard?
For every guard (web + api)
| File | Location |
|---|---|
| Migration | database/migrations/YYYY_MM_DD_HHmmss_create_{guard}s_table.php |
| Model | app/Models/{Guard}.php |
| Middleware | app/Http/Middleware/{Guard}AuthMiddleware.php |
| API Resource | app/Http/Resources/{Guard}Resource.php |
| Seeder | database/seeders/{Guard}Seeder.php |
| Route file | routes/{guard}.php |
Web guards only
| File | Location |
|---|---|
| Controller | app/Http/Controllers/{Guard}/{Guard}Controller.php |
| Auth Controller | app/Http/Controllers/{Guard}/Auth/AuthController.php |
| Dashboard view | resources/views/{guard}/dashboard.blade.php |
| Login view | resources/views/{guard}/Auth/login.blade.php |
API guards only
| File | Location |
|---|---|
| Auth Controller (JWT/Passport) | app/Http/Controllers/{Guard}/v1/Auth/AuthController.php |
What gets modified in your project?
| File | What changes |
|---|---|
config/auth.php |
Guard entry + provider entry added |
bootstrap/app.php (Laravel 11+) |
Route groups + middleware aliases added via ->withRouting() and ->withMiddleware() |
app/Http/Kernel.php (Laravel 10) |
$middlewareAliases entries added |
app/Providers/RouteServiceProvider.php (Laravel 10) |
Route groups registered in boot() |
database/seeders/DatabaseSeeder.php |
$this->call(GuardSeeder::class) added |
public/css/style.css |
Aurora UI stylesheet published (skipped if already exists) |
Generated file details
Migration columns
Every guard table gets these columns:
id, name, email (unique), email_verified_at, password,
gender (enum: male/female), status (enum: active/inactive),
age, birthday, phone, img, last_login_at, last_login_ip,
remember_token, timestamps
Model
Extends Authenticatable. Includes HasFactory, Notifiable, the correct $guard name, full $fillable, $hidden, and a casts() method.
Middleware
Web guard middleware redirects to the guard's login page when unauthenticated or inactive.
API guard middleware returns JSON 401 responses.
The alias is always {guard}.auth (e.g. admin.auth).
Web routes
GET /{guard}/login → login page
POST /{guard}/login/check → authenticate
POST /{guard}/logout → logout [protected]
GET /{guard}/dashboard → dashboard [protected]
API routes
POST /api/v1/auth/login-email → authenticate → returns token + resource
API Resource
Returns all model fields as JSON — useful in login responses and anywhere you need to return a guard's data cleanly.
Seeder
Creates a default user for the guard:
email: {guard}@example.com
password: Password@123
status: active
Views (web guards only)
A production-ready Aurora UI kit is published:
public/css/style.css— dark-glass design system (auto-skip if already present).dashboard.blade.php— full dashboard with sidebar, topbar, stat cards, chart, activity feed, table, and progress bars.login.blade.php— login card with email/password validation, error flash, and show/hide password toggle.
After running multi-guard:build
php artisan migrate php artisan db:seed
Then visit /{guardName}/login in your browser (web guards) or POST to /api/v1/auth/login-email (API guards).
Middleware alias reference
| Guard name | Alias |
|---|---|
admin |
admin.auth |
vendor |
vendor.auth |
customer |
customer.auth |
| (etc.) | {guard}.auth |
Use in routes like:
Route::group(['middleware' => ['admin.auth']], function () { // protected routes });
Auth config drivers
| Guard type | Driver |
|---|---|
| Web | session |
| API (JWT) | jwt |
| API (Passport) | passport |
License
MIT — free to use in any project, commercial or otherwise.
Contributing
Pull requests welcome. Please open an issue first to discuss what you'd like to change.
Credits
Built with ❤️ by Ebrahem Alwish. Aurora UI design system included.