Manage Users
Create and manage users for specific tenants with roles and permissions.
Create Tenant User
Section titled “Create Tenant User”Interactive Mode
Section titled “Interactive Mode”The easiest method is to use the interactive command:
php artisan tenant:user-createThe command will guide you through:
- Tenant selection (with numbered options)
- User name
- User email
- Password (or automatic generation)
- Role assignment
- Additional permission assignment
Non-Interactive Mode
Section titled “Non-Interactive Mode”For scripts and automation:
php artisan tenant:user-create \ --tenant="my-tenant" \ --name="John Doe" \ --email="john@example.com" \ --role="admin" \ --permissions="manage users,view dashboard"Available Options
Section titled “Available Options”--tenant=SLUG- Tenant ID or slug--name=NAME- User name--email=EMAIL- User email--password=PASSWORD- Password (auto-generated if not provided)--role=SLUG- Role slug (default: user)--permissions=LIST- Comma-separated list of permission slugs
Listing Options
Section titled “Listing Options”# List all available tenantsphp artisan tenant:user-create --list-tenants
# List available roles in a tenantphp artisan tenant:user-create --tenant="my-tenant" --list-roles
# List available permissions in a tenantphp artisan tenant:user-create --tenant="my-tenant" --list-permissionsWorking with Users in Code
Section titled “Working with Users in Code”User Model with HasRoles
Section titled “User Model with HasRoles”Add the HasRoles trait to your User model:
<?php
namespace App\Models;
use AngelitoSystems\FilamentTenancy\Concerns\HasRoles;use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable{ use HasRoles;
// Your model code...}Assign Roles
Section titled “Assign Roles”// Assign a role$user->assignRole('admin');
// Assign multiple roles$user->syncRoles(['admin', 'editor']);
// Remove a role$user->removeRole('admin');Verify Roles
Section titled “Verify Roles”// Check if user has a specific role$user->hasRole('admin');
// Check if user has any of the given roles$user->hasAnyRole(['admin', 'editor']);
// Check if user has all of the given roles$user->hasAllRoles(['admin', 'editor']);Manage Permissions
Section titled “Manage Permissions”// Give permission to user$user->givePermissionTo('manage users');
// Sync permissions$user->syncPermissions(['manage users', 'view dashboard']);
// Revoke permission$user->revokePermissionTo('manage users');
// Verify permissions$user->hasPermissionTo('manage users');$user->hasAnyPermission(['manage users', 'edit posts']);$user->hasAllPermissions(['manage users', 'view dashboard']);Create User Programmatically
Section titled “Create User Programmatically”use App\Models\User;use AngelitoSystems\FilamentTenancy\Facades\Tenancy;
// Switch to tenant contextTenancy::switchToTenant($tenant);
// Create user$user = User::create([ 'name' => 'John Doe', 'email' => 'john@example.com', 'password' => bcrypt('password'),]);
// Assign role$user->assignRole('admin');
// Assign permissions$user->givePermissionTo('manage users');Next Steps
Section titled “Next Steps”- Learn about models to work with tenant data
- Configure middleware for additional security