saadmughal/admin-auth-php
最新稳定版本:v1.3.8
Composer 安装命令:
composer require saadmughal/admin-auth-php
包简介
Admin authentication package for Laravel with Firebase notifications
README 文档
README
A complete Admin Authentication package for Laravel. Features include:
-
🔐 Admin login & registration
-
🔑 Password reset & email verification
-
🔔 Firebase push notifications for admins
-
⚡ Ready-to-use routes, controllers, and views
🚀 Installation & Setup
1. Install via Composer
composer require saadmughal/admin-auth-php
2. Register Service Provider
This package uses manual provider registration (to avoid errors on removal).
Laravel 9 & 10
Edit config/app.php and add to the providers array:
Mughal\AdminAuth\AdminAuthServiceProvider::class,
Laravel 11 & above
Edit bootstrap/providers.php:
return [ // other providers... Mughal\AdminAuth\AdminAuthServiceProvider::class, ];
3. Run Migrations
php artisan migrate
4. Add Guard & Provider
Add admin guard and provider in config/auth.php:
'guards' => [ 'admin' => [ 'driver' => 'session', 'provider' => 'admins', ], ], 'providers' => [ 'admins' => [ 'driver' => 'eloquent', 'model' => Mughal\AdminAuth\Models\Admin::class, ], ],
5. Dashboard Redirect
By default, after successful login, admins are redirected to /admin.
You can change this in config/adminauth.php:
'redirect_to' => '/dashboard',
After installing and migrating, you must define your own admin dashboard route.
Add this to routes/web.php in your Laravel project:
Route::middleware('auth:admin')->group(function () { Route::get('/dashboard', function () { return view('admin.dashboard'); }); });
6. Publish Config
After installing, publish the config file:
php artisan vendor:publish --provider="Mughal\AdminAuth\AdminAuthServiceProvider" --tag=config
Firebase Notifications (Optional)
If you want to send notifications to admins, configure Firebase:
- Add your Firebase JSON path in
.env:
ADMIN_FIREBASE_JSON=/full/path/to/firebase_project.json
- Save the admin’s FCM token when they log in
- If you have added the Firebase JSON file path in your .env file and the FCM token is being stored in the database, you can use the below function to send notifications to admins.
use Mughal\AdminAuth\Models\Admin; $admin = Admin::first(); $data = [ 'title' => 'New Alert', 'body' => 'You have a new notification!', 'description' => 'Notification details', 'type' => 'info' ]; $message = "Check your dashboard"; $admin->sendNotification($admin->id, $data, $message);
Visit in your browser:
http://localhost:8000/admin/login http://localhost:8000/admin/register
🗑️ Removal / Uninstall
To uninstall cleanly without errors:
-
Remove provider entry 1.1 Laravel 9 & 10 → remove from config/app.php 1.2 Laravel 11 → remove from bootstrap/providers.php
-
Remove the package
composer remove saadmughal/admin-auth-php
- Clear caches
php artisan config:clear php artisan route:clear php artisan view:clear php artisan cache:clear
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-18