saadmughal / admin-auth-php
Admin authentication package for Laravel with Firebase notifications
Requires
- php: ^8.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0|^13.0
- kreait/firebase-php: ^5.0
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