Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

walter_raponi's avatar

Help for a start project

Hello! I’ve been following the series on Filament, and now I want to start building an application.

A key feature for any application I work on is user management. Here’s what I need:

A super admin account that can create organizations. Organizations that can manage their own users, including assigning roles and permissions. Permissions that control CRUD operations on resources and actions accessible to the organization. Subscription-based or one-time payment options for accessing specific resources. Is there an example or best practice for achieving something like this in Filament without having to build everything from scratch? Are there any plugins that can help? Would this require multi-tenancy?

Thanks!

0 likes
1 reply
LaryAI's avatar
Level 58

To build an application with the features you've described using Filament, you can leverage several existing tools and best practices. Here's a step-by-step guide to help you get started:

  1. User Management with Roles and Permissions:

    • Use the spatie/laravel-permission package to manage roles and permissions. This package integrates well with Laravel and can be used to define roles like "super admin" and "organization admin."
    • Install the package via Composer:
      composer require spatie/laravel-permission
      
    • Publish the configuration file and run the migrations:
      php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
      php artisan migrate
      
    • Define roles and permissions in your application, and assign them to users.
  2. Super Admin and Organization Management:

    • Create a SuperAdmin role that has the ability to create and manage organizations.
    • Define an Organization model and a corresponding organizations table to store organization data.
    • Use Filament's resources to create a CRUD interface for managing organizations.
  3. Organization User Management:

    • Each organization can have its own users. You can achieve this by associating users with organizations through a foreign key in the users table.
    • Create roles specific to organizations, such as OrganizationAdmin, Member, etc., and assign them using the spatie/laravel-permission package.
  4. Permissions for CRUD Operations:

    • Define permissions for each CRUD operation on resources. For example, create-post, edit-post, delete-post, etc.
    • Assign these permissions to roles as needed.
  5. Subscription and Payment Options:

    • Consider using a package like laravel/cashier for handling subscriptions and payments.
    • Set up plans and pricing models, and integrate them with your application to control access to specific resources.
  6. Multi-Tenancy:

    • If you need to isolate data between organizations, consider implementing multi-tenancy. The tenancy/tenancy package is a popular choice for Laravel applications.
    • This will allow each organization to have its own database or schema, ensuring data separation.
  7. Filament Plugins:

    • Check the Filament plugins directory for any existing plugins that might help with user management or multi-tenancy. The community is active, and new plugins are frequently added.
  8. Example Setup:

    • Here's a basic example of how you might set up a role and assign it to a user:
      use Spatie\Permission\Models\Role;
      use Spatie\Permission\Models\Permission;
      use App\Models\User;
      
      // Create a role
      $role = Role::create(['name' => 'super-admin']);
      
      // Create a permission
      $permission = Permission::create(['name' => 'create-organization']);
      
      // Assign permission to role
      $role->givePermissionTo($permission);
      
      // Assign role to user
      $user = User::find(1);
      $user->assignRole('super-admin');
      

By following these steps, you can build a robust application with user management, roles, permissions, and payment options using Filament and Laravel.

Please or to participate in this conversation.