PHP code example of sridhar-s-subramanian / filament-dbview

1. Go to this page and download the library: Download sridhar-s-subramanian/filament-dbview 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/ */

    

sridhar-s-subramanian / filament-dbview example snippets


use SridharSSubramanian\FilamentDbview\DbviewPlugin;

public function panel(Panel $panel): Panel
{
    return $panel->plugin(DbviewPlugin::make());
}

$panel->plugin(
    DbviewPlugin::make()
        ->history() // persist + show per-user query history
);

$panel->plugin(
    DbviewPlugin::make()
        ->allTables() // list + allow every table on allowed connections
        // Optional: still block a few sensitive framework tables
        ->denyTables(['password_reset_tokens', 'sessions', 'personal_access_tokens']),
);

// config/filament-dbview.php
'models' => [
    'paths' => [
        app_path('Models'),
        // app_path('Domain/Orders/Models'),
    ],

    // Global denylist — these models never appear in the Browser / models-scope Runner
    'exclude' => [
        // \App\Models\PersonalAccessToken::class,
        // \App\Models\Passport\Token::class,
        // \App\Models\Admin::class,
    ],

    'cache' => [
        'enabled' => env('FILAMENT_DBVIEW_CACHE', true),
        'store' => null,
        'key' => 'filament-dbview.registry',
        'ttl' => 3600, // null = cache until filament-dbview:clear
    ],
],

// config/filament-dbview.php
'audit' => [
    // null = Laravel's default logger. Prefer a dedicated channel in production.
    'log_channel' => env('FILAMENT_DBVIEW_LOG_CHANNEL', null),

    // true  = 'FILAMENT_DBVIEW_LOG_SQL', true), FILTER_VALIDATE_BOOLEAN),
],

'channels' => [
    'dbview' => [
        'driver' => 'daily',
        'path' => storage_path('logs/dbview.log'),
        'level' => env('LOG_LEVEL', 'debug'),
        'days' => 14,
    ],
],

use Illuminate\Support\Facades\Gate;

Gate::define('viewDbview', function ($user) {
    return (bool) ($user->is_admin ?? false);
});

Gate::define('runDbviewQueries', function ($user) {
    return (bool) ($user->is_admin ?? false);
});

// Optional: limit which tables appear / can be queried
Gate::define('viewDbviewTable', function ($user, string $table) {
    return in_array($table, ['users', 'orders', 'posts'], true);
});

// Optional: who may download CSV/JSON from the Query Runner
Gate::define('exportDbview', function ($user) {
    return (bool) ($user->is_admin ?? false);
});

use Illuminate\Support\Facades\Gate;

Gate::define('viewDbview', fn ($user) => $user->can('dbview.access'));
Gate::define('runDbviewQueries', fn ($user) => $user->can('dbview.query'));
Gate::define('viewDbviewTable', fn ($user, string $table) =>
    $user->can('dbview.tables.*') || $user->can("dbview.tables.{$table}")
);
Gate::define('exportDbview', fn ($user) => $user->can('dbview.export'));

'authorization' => [
    // Leave as null to allow every authenticated panel user (default).
    'gate' => 'viewDbview',

    // Optional: tighter control for the Query Runner (raw SELECT console).
    // If set, the user must pass both `gate` and this ability.
    'query_runner_gate' => 'runDbviewQueries',

    // Optional: hide / block tables the user may not see.
    // The Gate is invoked as: allows('viewDbviewTable', $tableName)
    'table_gate' => 'viewDbviewTable',

    // Optional: who may download CSV/JSON (null = any user who can run queries).
    'export_gate' => 'exportDbview',
],

'authorization' => [
    'gate' => env('FILAMENT_DBVIEW_GATE'),              // null when unset → allow
    'query_runner_gate' => env('FILAMENT_DBVIEW_QUERY_GATE'),
    'table_gate' => env('FILAMENT_DBVIEW_TABLE_GATE'),
    'export_gate' => env('FILAMENT_DBVIEW_EXPORT_GATE'),
],

'models' => [
    'paths'   => [app_path('Models')], // see Model discovery section
    'exclude' => [],                    // FQCNs never registered
    'cache'   => ['enabled' => true, 'ttl' => 3600, /* store, key */],
],

'connections' => [
    'allowed'   => null,                 // null = every connection a model uses
    'read_only' => [],                   // e.g. ['mysql' => 'mysql_readonly']
],

'limits' => [
    'default_rows'     => 100,
    'max_rows'         => 1000,
    'timeout'          => 15,            // statement timeout (seconds)
    'max_result_bytes' => 5 * 1024 * 1024,
],

'redact' => ['password', '*_token', '*_secret', /* … */],

'features' => [
    'query_runner'         => true,
    'explain'              => true,      // EXPLAIN / EXPLAIN ANALYZE buttons
    'structure'            => true,      // "Show structure" (columns/indexes/FKs)
    'export'               => true,      // false = hide CSV/JSON for everyone
    'history'              => false,     // feature opt-in (table still migrates); ->history()
    'saved_queries'        => true,
    'relationship_preview' => true,      // FK preview actions in the browser
],

'query_runner' => [
    'scope' => 'models',                 // 'models' | 'connection' (allTables)
    'deny'  => [],                       // optional blocks in connection scope only
],

// Authorization is allow-by-default; set ability names to opt in (see Authorization section).
'authorization' => [
    'gate'              => null,         // e.g. 'viewDbview'
    'query_runner_gate' => null,         // e.g. 'runDbviewQueries'
    'table_gate'        => null,         // e.g. 'viewDbviewTable' (receives table name)
    'export_gate'       => null,         // e.g. 'exportDbview' (CSV/JSON)
],

'audit' => [
    'log_channel' => null,               // e.g. 'dbview' — dedicated Laravel log channel
    'log_sql'     => true,               // false = omit SQL body from PSR-3 context
],
bash
composer vendor:publish --tag="filament-dbview-config"
php artisan vendor:publish --tag="filament-dbview-migrations"
php artisan migrate
bash
php artisan filament-dbview:clear
bash
php artisan vendor:publish --tag="filament-dbview-config"
bash
php artisan filament-dbview:clear