Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Filament Accounts Laravel Package

tomatophp/filament-accounts

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require tomatophp/filament-accounts
    

    Publish the package assets and config:

    php artisan vendor:publish --provider="TomatoPHP\FilamentAccounts\FilamentAccountsServiceProvider" --tag="filament-accounts-config"
    php artisan vendor:publish --provider="TomatoPHP\FilamentAccounts\FilamentAccountsServiceProvider" --tag="filament-accounts-migrations"
    

    Run migrations:

    php artisan migrate
    
  2. Register the Plugin Add to app/Providers/Filament/AdminPanelProvider.php:

    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                \TomatoPHP\FilamentAccounts\FilamentAccountsPlugin::make(),
            ]);
    }
    
  3. First Use Case Create a multi-auth system with a single users table:

    // config/filament-accounts.php
    'auth' => [
        'drivers' => [
            'admin' => [
                'guard' => 'admin',
                'model' => \App\Models\User::class,
            ],
            'client' => [
                'guard' => 'client',
                'model' => \App\Models\User::class,
            ],
        ],
    ],
    

    Access the Filament panel (/admin/accounts) to manage accounts.


Implementation Patterns

Core Workflows

  1. Account Creation Use the built-in Filament form to create accounts with multiple roles/guards:

    // Example: Create an admin account
    $account = \TomatoPHP\FilamentAccounts\Models\Account::create([
        'email' => 'admin@example.com',
        'password' => bcrypt('secure123'),
        'accounts' => [
            'admin' => true,
            'client' => false,
        ],
    ]);
    
  2. Switching Auth Guards Dynamically switch guards in middleware or controllers:

    use TomatoPHP\FilamentAccounts\Facades\FilamentAccounts;
    
    FilamentAccounts::setGuard('client'); // Switch to client guard
    
  3. Integration with Filament Policies Extend Filament policies to restrict access per guard:

    // app/Policies/AdminPolicy.php
    public function viewAny(User $user)
    {
        return FilamentAccounts::hasGuard('admin');
    }
    
  4. Customizing Account Fields Override default fields via a service provider:

    public function boot()
    {
        FilamentAccounts::extendAccountForm(function (Form $form) {
            $form->schema([
                // Custom fields here
            ]);
        });
    }
    

Advanced Patterns

  • Multi-Guard Middleware

    public function handle(Request $request, Closure $next)
    {
        if (!FilamentAccounts::hasGuard('admin')) {
            abort(403);
        }
        return $next($request);
    }
    
  • Seeding Multi-Accounts

    // database/seeders/AccountSeeder.php
    FilamentAccounts::createAccount([
        'email' => 'superadmin@example.com',
        'accounts' => [
            'admin' => true,
            'client' => true,
            'superadmin' => true,
        ],
    ]);
    
  • API Integration Use the FilamentAccounts facade to validate requests:

    public function login(Request $request)
    {
        $guard = $request->input('guard', 'admin');
        if (!FilamentAccounts::hasGuard($guard)) {
            return response()->json(['error' => 'Invalid guard'], 400);
        }
        // Proceed with auth
    }
    

Gotchas and Tips

Common Pitfalls

  1. Guard Mismatch

    • Issue: Forgetting to update config/filament-accounts.php after adding new guards.
    • Fix: Run php artisan config:clear or verify guards in the Filament UI under Settings > Accounts.
  2. Migration Conflicts

    • Issue: Custom users table structure conflicts with package migrations.
    • Fix: Extend the migration or use --force (backup first):
      php artisan migrate --force
      
  3. Caching Headaches

    • Issue: Guard changes not reflecting due to cached routes/policies.
    • Fix: Clear caches:
      php artisan optimize:clear
      php artisan view:clear
      
  4. Permission Denied

    • Issue: Users can’t access Filament despite correct guard setup.
    • Fix: Check config/filament.php for auth middleware and ensure guards are registered in AuthServiceProvider.

Debugging Tips

  • Log Guard Switches Enable debug mode in config/filament-accounts.php:

    'debug' => env('APP_DEBUG', false),
    

    Check logs for guard-related events.

  • Inspect Account Data Use Tinker to verify account data:

    php artisan tinker
    >>> \TomatoPHP\FilamentAccounts\Models\Account::first()->accounts
    
  • Filament Plugin Isolation If the plugin doesn’t appear, verify:

    • The FilamentAccountsPlugin is registered in AdminPanelProvider.
    • No JavaScript errors (check browser console).

Extension Points

  1. Custom Account Models Override the default model by binding it in a service provider:

    FilamentAccounts::extendModel(\App\Models\CustomAccount::class);
    
  2. Dynamic Guard Assignment Use events to assign guards dynamically:

    FilamentAccounts::listen('account.created', function ($account) {
        if ($account->email === 'admin@example.com') {
            $account->assignGuard('superadmin');
        }
    });
    
  3. API Resource Integration Extend the default API resource:

    FilamentAccounts::extendApiResource(function (ApiResource $resource) {
        $resource->schema([
            // Custom API fields
        ]);
    });
    
  4. Localization Override translations:

    // resources/lang/en/filament-accounts.php
    return [
        'accounts' => [
            'list' => 'My Accounts',
        ],
    ];
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium