PHP code example of dbflowlabs / filament

1. Go to this page and download the library: Download dbflowlabs/filament library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dbflowlabs / filament example snippets


'auth' => [
    'model' => env('DBFLOW_AUTH_MODEL', App\Models\User::class),
    'guard' => env('DBFLOW_AUTH_GUARD', 'web'),
    'table' => env('DBFLOW_AUTH_TABLE', 'users'),
    // ...
],

use DbflowLabs\Core\Actions\SyncWorkflowDefinitions;

app(SyncWorkflowDefinitions::class)->handle();

use DbflowLabs\Core\DBFlow;
use DbflowLabs\Core\Services\AssigneeResolverRegistry;

DBFlow::registerAssigneeResolver(
    app(AssigneeResolverRegistry::class),
    'finance_team',
    $myAssigneeResolver,
);



declare(strict_types=1);

namespace App\Providers\Filament;

use DbflowLabs\Filament\Support\DBFlowFilamentPanel;
use Filament\Panel;
use Filament\PanelProvider;

final class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        $panel = $panel
            ->id('admin')
            ->path('admin') // or '' when the panel is mounted at the site root
            // your pages, resources, middleware, branding...
        ;

        if ($this->shouldRegisterDbflow()) {
            return DBFlowFilamentPanel::register($panel);
        }

        return $panel;
    }

    private function shouldRegisterDbflow(): bool
    {
        if (! (bool) config('dbflow-filament.enabled', true)) {
            return false;
        }

        // Optional host product flag — replace with your application's config key.
        return (bool) config('myapp.workflow.filament_enabled', true);

        // Some hosts also gate Core runtime separately via config('dbflow.enabled').
        // DBFlowFilamentPanel does not read dbflow.enabled; that flag affects action buttons at runtime.
    }
}

use DbflowLabs\Filament\Support\DBFlowFilamentPanel;

$panel->pages([
    ...$panel->getPages(),
    ...DBFlowFilamentPanel::pageClasses(),
]);

$panel->resources([
    ...$panel->getResources(),
    ...DBFlowFilamentPanel::resourceClasses(),
]);

// config/dbflow-filament.php

'permission_checker_class' => \App\Filament\Workflow\HostPermissionChecker::class,



declare(strict_types=1);

namespace App\Filament\Workflow;

use App\Services\HostPermissionService;
use DbflowLabs\Filament\Contracts\PermissionChecker;
use Illuminate\Contracts\Auth\Authenticatable;

final class HostPermissionChecker implements PermissionChecker
{
    public function __construct(
        private readonly HostPermissionService $permissions,
    ) {}

    public function can(mixed $user, string $ability, mixed $record = null): bool
    {
        if (! $user instanceof Authenticatable) {
            return false;
        }

        return match ($ability) {
            'dbflow.tasks.view' => $this->permissions->allows($user, 'workflow.tasks.view'),
            'dbflow.tasks.approve',
            'dbflow.tasks.reject',
            'dbflow.tasks.reassign' => $this->permissions->allows($user, 'workflow.tasks.operate'),
            'dbflow.workflow_instances.view',
            'dbflow.workflow_instances.view_any' => $this->permissions->allows($user, 'workflow.instances.view'),
            'dbflow.workflow_instances.cancel' => $this->permissions->allows($user, 'workflow.instances.cancel'),
            'dbflow.definitions.view',
            'dbflow.definitions.create',
            'dbflow.definitions.update',
            'dbflow.definitions.delete',
            'dbflow.definitions.validate',
            'dbflow.definitions.publish',
            'dbflow.definitions.disable',
            'dbflow.definitions.enable',
            'dbflow.definitions.archive',
            'dbflow.definitions.copy' => $this->permissions->allows($user, 'workflow.definitions.manage'),
            'dbflow.delegations.view_any' => $this->permissions->allows($user, 'workflow.delegations.view'),
            'dbflow.sla_events.view' => $this->permissions->allows($user, 'workflow.sla.view'),
            'dbflow.action_executions.view_any',
            'dbflow.action_executions.view',
            'dbflow.action_attempts.view' => $this->permissions->allows($user, 'workflow.actions.view'),
            'dbflow.webhook_metadata.view' => $this->permissions->allows($user, 'workflow.webhooks.view'),
            default => false,
        };
    }
}

// config/dbflow-filament.php

'user_assignee_options_resolver_class' => \App\Filament\Workflow\HostUserAssigneeOptionsResolver::class,
'user_model' => App\Models\User::class, // optional; falls back to Core auth model



declare(strict_types=1);

namespace App\Filament\Workflow;

use App\Models\User;
use DbflowLabs\Filament\Contracts\UserAssigneeOptionsResolver;
use Illuminate\Database\Eloquent\Model;

final class HostUserAssigneeOptionsResolver implements UserAssigneeOptionsResolver
{
    /**
     * @return array<string, string>
     */
    public function options(): array
    {
        $modelClass = config('dbflow-filament.user_model') ?? config('dbflow.auth.model');

        if (! is_string($modelClass) || ! class_exists($modelClass) || ! is_subclass_of($modelClass, Model::class)) {
            return [];
        }

        $nameAttribute = (string) config('dbflow-filament.user_name_attribute', 'name');

        return $modelClass::query()
            ->orderBy($nameAttribute)
            ->get(['id', $nameAttribute, 'email'])
            ->mapWithKeys(function (Model $user) use ($nameAttribute): array {
                $label = filled($user->{$nameAttribute} ?? null)
                    ? (string) $user->{$nameAttribute}
                    : (string) ($user->email ?? $user->getKey());

                return [(string) $user->getKey() => $label];
            })
            ->all();
    }
}

DbflowLabs\Filament\Contracts\WorkflowDefinitionEditorResolver
bash
   php artisan vendor:publish --tag=dbflow-config
   php artisan vendor:publish --tag=dbflow-filament-config
   
bash
php artisan vendor:publish --tag=dbflow-config
php artisan vendor:publish --tag=dbflow-filament-config
bash
php artisan vendor:publish --tag=dbflow-filament-views
bash
php artisan vendor:publish --tag=dbflow-filament-translations
bash
php artisan migrate
bash
php artisan vendor:publish --tag=dbflow-config
bash
php artisan dbflow:sync
php artisan dbflow:validate --strict
bash
php artisan vendor:publish --tag=dbflow-filament-config