Admin middleware
Role-based access to the admin panel through Spatie Permission, replacing the is_admin column fallback the core ships with.
What it adds
| File | Purpose |
|---|---|
app/Http/Middleware/EnsureUserIsAdmin.php | Allows the request when the user has the admin role |
database/seeders/AdminRoleSeeder.php | Creates the admin and user roles |
HasRoles in app/Models/Concerns/UiKitUser.php | Added to the generated trait, so $user->hasRole('admin') works |
Install
php artisan ui-kit:install-module admin-middleware
Composer: spatie/laravel-permission:^6.10, required by the installer before the stubs are copied.
What the installer changes
- Publishes Spatie's config and migrations and runs
migrate. - Runs
AdminRoleSeeder. - Swaps
EnsureIsAdminFallback::classforApp\Http\Middleware\EnsureUserIsAdmin::classin themiddlewarelist ofconfig/admin.php. - Regenerates the
UiKitUsertrait withHasRolesand re-applies it toapp/Models/User.php.
No routes, no navigation entries, no screens.
After install
Grant the role to your account:
php artisan ui-kit:make-admin [email protected]
make-admin assigns the role and also sets is_admin when that column exists, so an app that installs this module later keeps working for users who were admins before.
Using roles elsewhere
Everything Spatie offers is available: $user->assignRole('editor'), @role('admin') in Blade, role:admin middleware on your own routes. The admin routes keep using EnsureUserIsAdmin, which is a plain class in your app; edit it to check a permission instead of a role if that fits better.
Removing
Restore \Shipbytes\UiKit\Http\Middleware\EnsureIsAdminFallback::class in config/admin.php, delete the middleware and seeder, remove HasRoles from the trait, remove admin-middleware from installed_modules in config/ui-kit.php, and composer remove spatie/laravel-permission after rolling back its migration.