This starter kit includes a complete admin system for managing users, roles, and permissions, built on top of Spatie Laravel Permission. It ships with a separate admin dashboard, a seeded permission set, a Super Admin role, and user impersonation.
- Admin dashboard - A separate backend area at
/admin, protected by permissions - User management - Create, view, edit, and delete users; assign roles
- Role management - Create, edit, and delete roles; assign permissions to roles
- Permission management - Create, edit, and delete permissions
- Seeded defaults - A sensible default permission set and a Super Admin role out of the box
- Super Admin creation command - Create your first admin user from the CLI
- Impersonation - Log in as any other user and switch back, gated by a permission
- Search & pagination - All admin list views support searching and per-page settings
database/seeders/PermissionSeeder.php seeds the following permissions:
| Permission | Grants |
|---|---|
access dashboard |
Access to the admin dashboard at /admin |
impersonate |
Ability to impersonate other users |
view users |
View the users list and individual users |
create users |
Create new users |
update users |
Edit existing users |
delete users |
Delete users |
view roles |
View the roles list |
create roles |
Create new roles |
update roles |
Edit existing roles |
delete roles |
Delete roles |
view permissions |
View the permissions list |
create permissions |
Create new permissions |
update permissions |
Edit existing permissions |
delete permissions |
Delete permissions |
Run the seeders with:
php artisan db:seedDatabaseSeeder calls PermissionSeeder and RoleSeeder in order. Both seeders use updateOrCreate, so they are safe to re-run.
database/seeders/RoleSeeder.php creates a role named Super Admin and assigns it all seeded permissions. Note that this is a plain role with every permission attached - there is no implicit Gate::before bypass, so newly created permissions are not automatically granted to the role. Re-run the seeders (or edit the role in /admin/roles) to grant new permissions to the Super Admin role.
Use the included Artisan command:
php artisan app:create-super-adminThe command (app/Console/Commands/CreateSuperAdminCommand.php) will interactively:
- Ask whether you want to create a super admin user
- Ask for the user's name, email, and password
- Ask whether the user should be a super admin
- Create the user (with locale
en) and, if confirmed, assign theSuper Adminrole
This command is also run automatically at the end of composer create-project (see the post-create-project-cmd script in composer.json). Make sure you have run php artisan db:seed first, so the Super Admin role exists.
The admin area lives under /admin and requires authentication. Each section is protected by can: middleware on the route and an authorize() call in the Livewire component:
| Route | Component | Required permission |
|---|---|---|
GET /admin |
Admin\Index |
access dashboard |
GET /admin/users |
Admin\Users |
view users |
GET /admin/users/create |
Admin\Users\CreateUser |
create users |
GET /admin/users/{user} |
Admin\Users\ViewUser |
view users |
GET /admin/users/{user}/edit |
Admin\Users\EditUser |
update users |
GET /admin/roles |
Admin\Roles |
view roles |
GET /admin/roles/create |
Admin\Roles\CreateRole |
create roles |
GET /admin/roles/{role}/edit |
Admin\Roles\EditRole |
update roles |
GET /admin/permissions |
Admin\Permissions |
view permissions |
GET /admin/permissions/create |
Admin\Permissions\CreatePermission |
create permissions |
GET /admin/permissions/{permission}/edit |
Admin\Permissions\EditPermission |
update permissions |
Delete actions are handled inside the list components (Admin\Users, Admin\Roles, Admin\Permissions) and are authorized against delete users, delete roles, and delete permissions respectively.
- Navigate to
/admin/users - Search users by name or email, or filter by role
- Click Create to add a new user - set name, email, locale, and roles. New users are created with a random password (they can use the password reset flow to set their own)
- Click Edit on a user to update their details and sync their roles
- Click Delete to remove a user
- Navigate to
/admin/roles - Click Create to add a role - give it a name and select at least one permission
- Click Edit to rename a role or change its permissions
- Click Delete to remove a role
- Navigate to
/admin/permissions - Create, edit, or delete permissions by name
Note: Permissions created in the UI are not automatically attached to any role - assign them via the role edit screen.
Users with the impersonate permission can log in as any other user from the users list.
- On
/admin/users, an Impersonate button is shown next to each user (except yourself) for users who have theimpersonatepermission - Clicking it sends a
POSTto/impersonate/{user}(ImpersonationController::store), which:- Authorizes the
impersonatepermission - Stores your own user ID in the session as
admin_user_id - Logs you in as the target user and redirects to the dashboard
- Authorizes the
- While impersonating, a banner with a stop impersonating form is shown in the app layouts (sidebar and frontend)
- Stopping sends a
DELETEto/impersonate/stop(ImpersonationController::destroy), which logs you back in as the original user, clearsadmin_user_idfrom the session, and redirects to/admin
POST /impersonate/{user}- Start impersonating (impersonate.store, protected bycan:impersonatemiddleware)DELETE /impersonate/stop- Stop impersonating (impersonate.destroy)
Impersonation requires the impersonate permission. It is enforced both by the can:impersonate route middleware and by $this->authorize('impersonate') in the controller. The Super Admin role has this permission by default.
Console Commands:
app/Console/Commands/CreateSuperAdminCommand.php-php artisan app:create-super-admin
Controllers:
app/Http/Controllers/ImpersonationController.php- Start/stop impersonation
Livewire Components:
app/Livewire/Admin/Index.php- Admin dashboardapp/Livewire/Admin/Users.php- Users list (search, role filter, delete)app/Livewire/Admin/Users/CreateUser.phpapp/Livewire/Admin/Users/EditUser.phpapp/Livewire/Admin/Users/ViewUser.phpapp/Livewire/Admin/Roles.php- Roles list (search, delete)app/Livewire/Admin/Roles/CreateRole.phpapp/Livewire/Admin/Roles/EditRole.phpapp/Livewire/Admin/Permissions.php- Permissions list (search, delete)app/Livewire/Admin/Permissions/CreatePermission.phpapp/Livewire/Admin/Permissions/EditPermission.php
Seeders:
database/seeders/PermissionSeeder.phpdatabase/seeders/RoleSeeder.phpdatabase/seeders/DatabaseSeeder.php
Views:
resources/views/livewire/admin/- Admin views (using thecomponents.layouts.adminlayout)resources/views/components/layouts/app/sidebar.blade.php- Stop-impersonating bannerresources/views/components/layouts/app/frontend.blade.php- Stop-impersonating banner
Routes:
routes/web.php- Admin and impersonation routes
Language Files:
lang/{locale}/users.php,lang/{locale}/roles.php,lang/{locale}/permissions.php
Authorization is enforced in two layers:
- Route middleware - e.g.
->middleware('can:view users')inroutes/web.php - Component/controller authorization -
$this->authorize('...')inmount()and in every mutating action
This means even Livewire actions that bypass the route (e.g. delete actions on list pages) are still permission-checked.
Test coverage for the admin system lives in:
tests/Feature/Livewire/Admin/IndexTest.phptests/Feature/Livewire/Admin/UsersTest.phpandtests/Feature/Livewire/Admin/Users/tests/Feature/Livewire/Admin/RolesTest.phpandtests/Feature/Livewire/Admin/Roles/tests/Feature/Livewire/Admin/PermissionsTest.phpandtests/Feature/Livewire/Admin/Permissions/tests/Feature/Command/CreateSuperAdminCommandTest.php
Run the admin-related tests:
php artisan test --filter=AdminOr run all tests:
php artisan testQ: Does the Super Admin role automatically get new permissions?
A: No. The role is granted all permissions that exist when RoleSeeder runs. If you add permissions later, assign them to the role via /admin/roles or re-run php artisan db:seed.
Q: Can I rename or remove the seeded permissions?
A: Yes, but the permission names are referenced by routes (can: middleware), component authorize() calls, and Blade @can directives. If you rename a permission, update those references too.
Q: What password do users created in the admin get?
A: A random 16-character password. They should use the "Forgot password" flow to set their own.
Q: Can an impersonating admin impersonate another user while already impersonating?
A: The impersonated user would need the impersonate permission for the button to appear. Note that starting a new impersonation overwrites the stored admin_user_id, so chained impersonation returns you to the most recent impersonator, not the original admin.
Q: How do I check permissions in my own code?
A: Use the standard Laravel/Spatie APIs: $user->can('view users'), @can('impersonate') in Blade, ->middleware('can:view roles') on routes, or $this->authorize('update users') in components and controllers.