cuonggt / laravel-dibi
为您的Laravel应用程序提供优雅的GUI数据库管理工具。
Requires
- php: ^7.3|^8.0.2
- ext-json: *
- laravel/framework: ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- ramsey/uuid: ^3.8|^4.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.4
- orchestra/testbench: ^4.0|^5.0|^6.0|^7.0|^8.0
README
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许可协议授权。