saadmughal/admin-auth-php

Admin authentication package for Laravel with Firebase notifications

Maintainers

Package info

github.com/saadey7/admin-auth-php

pkg:composer/saadmughal/admin-auth-php

Statistics

Installs: 12

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.3.8 2025-08-21 05:37 UTC

This package is auto-updated.

Last update: 2026-03-21 07:01:47 UTC


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