ebrahemalwish/laravel-multi-guard 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ebrahemalwish/laravel-multi-guard

最新稳定版本:v1.0.1

Composer 安装命令:

composer require ebrahemalwish/laravel-multi-guard

包简介

A Laravel package to scaffold multiple authentication guards (web, JWT, Passport) with migrations, models, middleware, controllers, routes, seeders, and views.

README 文档

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:

  1. How many guards do you want? — enter a number (anything else is rejected with an error).
  2. Guard name — e.g. admin, vendor, customer.
  3. Guard typeweb or api.
  4. (API only) API driverjwt or passport.

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.

ebrahemalwish/laravel-multi-guard 适用场景与选型建议

ebrahemalwish/laravel-multi-guard 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 2, 最近一次更新时间为 2026 年 03 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「auth」 「laravel」 「passport」 「jwt」 「guard」 「multi-guard」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ebrahemalwish/laravel-multi-guard 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ebrahemalwish/laravel-multi-guard 我们能提供哪些服务?
定制开发 / 二次开发

基于 ebrahemalwish/laravel-multi-guard 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 39
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-11