saadmughal/admin-auth-php 问题修复 & 功能扩展

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

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

saadmughal/admin-auth-php

最新稳定版本:v1.3.8

Composer 安装命令:

composer require saadmughal/admin-auth-php

包简介

Admin authentication package for Laravel with Firebase notifications

README 文档

README

Latest Version on Packagist Total Downloads License PHP Version Require

A complete Admin Authentication package for Laravel. Features include:

  1. 🔐 Admin login & registration

  2. 🔑 Password reset & email verification

  3. 🔔 Firebase push notifications for admins

  4. ⚡ 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:

  1. Add your Firebase JSON path in .env:
ADMIN_FIREBASE_JSON=/full/path/to/firebase_project.json
  1. Save the admin’s FCM token when they log in
  2. 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:

  1. Remove provider entry 1.1 Laravel 9 & 10 → remove from config/app.php 1.2 Laravel 11 → remove from bootstrap/providers.php

  2. Remove the package

composer remove saadmughal/admin-auth-php
  1. Clear caches
php artisan config:clear
php artisan route:clear
php artisan view:clear
php artisan cache:clear

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-18