cuonggt/laravel-dibi

为您的Laravel应用程序提供优雅的GUI数据库管理工具。

v0.4.0 2024-06-09 02:35 UTC

This package is auto-updated.

Last update: 2024-09-10 07:09:09 UTC


README

Build Status License

screenshot

Laravel Dibi是一款为您的Laravel应用程序提供的优雅GUI数据库管理工具。它提供了快速访问本地/开发服务器上的数据库,无需安装任何其他应用程序。

安装

您可以使用Composer包管理器将Dibi安装到项目中

composer require cuonggt/laravel-dibi

安装Dibi后,使用dibi:install Artisan命令发布其资产

php artisan dibi:install

目前,Dibi仅支持MySQL。我希望在不久的将来能够支持SQL Server、PostgreSQL、SQLite等其他数据库引擎。

Dibi默认使用数据库连接名称mysql进行连接。如果您想使用其他数据库连接名称,可以使用Dibi::useDatabaseConnectionName方法。您可以从应用程序的App\Providers\DibiServiceProvider类的boot方法调用此方法

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    parent::boot();

    Dibi::useDatabaseConnectionName('custom_mysql');
}

仪表板授权

Dibi在/dibi URI上公开了一个仪表板。默认情况下,您只能在local环境中访问此仪表板。然而,在您的app/Providers/DibiServiceProvider.php文件中,有一个授权网关定义。此授权网关控制对Dibi在非本地环境中的访问。您可以根据需要修改此网关,以限制对您的Dibi安装的访问

/**
 * Register the Dibi gate.
 *
 * This gate determines who can access Dibi in non-local environments.
 *
 * @return void
 */
protected function gate()
{
    Gate::define('viewDibi', function ($user) {
        return in_array($user->email, [
            'admin@example.com',
        ]);
    });
}

升级Dibi

当升级到Dibi的新主要版本时,仔细审查升级指南非常重要。此外,当升级到任何新的Dibi版本时,您应重新发布Dibi的资产

php artisan dibi:publish

为了保持资产的最新状态并避免未来的更新问题,您可以在应用程序的composer.json文件中将dibi:publish命令添加到post-update-cmd脚本中

{
    "scripts": {
        "post-update-cmd": [
            "@php artisan dibi:publish --ansi"
        ]
    }
}

自定义中间件

如果需要,您可以通过更新config/dibi.php文件来自定义Dibi路由使用的中间件堆栈。如果您尚未发布Dibi的配置文件,可以使用vendor:publish Artisan命令进行发布

php artisan vendor:publish --tag=dibi-config

一旦配置文件已发布,您可以通过调整此文件中的middleware配置选项来编辑Dibi的中间件

/*
|--------------------------------------------------------------------------
| Dibi Route Middleware
|--------------------------------------------------------------------------
|
| These middleware will be assigned to every Dibi route - giving you
| the chance to add your own middleware to this list or change any of
| the existing middleware. Or, you can simply stick with this list.
|
*/

'middleware' => [
    'web',
    EnsureUserIsAuthorized::class,
    EnsureUpToDateAssets::class
],

仅本地安装

如果您计划仅使用Dibi来辅助本地开发,可以使用--dev标志安装Dibi

composer require cuonggt/laravel-dibi --dev
php artisan dibi:install

运行dibi:install后,您应从应用程序的config/app.php配置文件中删除DibiServiceProvider服务提供者注册。相反,在App\Providers\AppServiceProvider类的register方法中手动注册Dibi的服务提供者。我们将确保当前环境是特定环境之一,然后注册提供者

/**
 * Register any application services.
 *
 * @return void
 */
public function register()
{
    if ($this->app->environment('local', 'develop', 'staging')) {
        $this->app->register(\Cuonggt\Dibi\DibiServiceProvider::class);
        $this->app->register(DibiServiceProvider::class);
    }
}

最后,您还应该通过向您的composer.json文件中添加以下内容来防止Dibi包自动发现

"extra": {
    "laravel": {
        "dont-discover": [
            "cuonggt/laravel-dibi"
        ]
    }
},

许可协议

Laravel Dibi是开源软件,根据MIT许可协议授权。