laranail/db-console
A database console for Laravel: browse tables, run ad-hoc SQL, and inspect results in a lightweight Artisan-served UI. Configurable connection allowlists, read-only mode, and query guards keep production data safe, while Composer install and a published config get you running in minutes.
Installation
composer require laranail/db-console
php artisan vendor:publish --provider="Laranail\DbConsole\DbConsoleServiceProvider" --tag="db-console:migrations"
php artisan migrate
Configuration
Edit config/db-console.php to define:
servers (database connections from config/database.php)users (default admin credentials or OAuth providers)api (REST endpoint settings, e.g., route_prefix)First Use Case Run the CLI tool to manage databases:
php artisan db-console:server list
php artisan db-console:user create --name=admin [email protected] --password=secure123
Database Management
php artisan db-console:database create --name=app_prod --server=mysql_prod
php artisan db-console:database delete --name=app_prod --server=mysql_prod
php artisan db-console:backup create --name=app_prod_backup --server=mysql_prod
php artisan db-console:backup restore --name=app_prod_backup --server=mysql_prod
User & Privilege Management
php artisan db-console:user assign-role --user=dev_team --role=developer --server=mysql_prod
php artisan db-console:permission grant --user=dev_team --permission=SELECT --database=app_prod --server=mysql_prod
REST API Integration
POST /api/db-console/servers (Create a server)GET /api/db-console/users/{id}/databases (List databases for a user)config/db-console.php).Event-Driven Extensions
Listen to events like database.created or user.assigned:
// In EventServiceProvider
protected $listen = [
'Laranail\DbConsole\Events\DatabaseCreated' => [
'App\Listeners\LogDatabaseCreation',
],
];
Server Configuration Mismatch
config/database.php connections match the servers defined in config/db-console.php.php artisan db-console:server validate.Permission Overwrites
GRANT statements bypass db-console and may break role assignments.php artisan db-console:permission sync to reconcile.Backup Storage
storage/app/db-backups by default. Ensure this directory is writable and has sufficient space.backup_disk in config/db-console.php to use cloud storage (e.g., S3).Rate Limiting
throttle to routes/api.php:
Route::middleware(['throttle:60,1'])->group(function () {
Route::apiResource('db-console/servers', 'ServerController');
});
debug to true in config/db-console.php and check storage/logs/laravel.log.DB::enableQueryLog() before operations to inspect raw SQL:
DB::enableQueryLog();
$database = \Laranail\DbConsole\Models\Database::create(...);
dd(DB::getQueryLog());
Custom Commands Extend the CLI with new commands by publishing the command stubs:
php artisan vendor:publish --provider="Laranail\DbConsole\DbConsoleServiceProvider" --tag="db-console:commands"
Example: Add a php artisan db-console:database optimize command.
API Resources
Override default API responses by extending Laranail\DbConsole\Http\Resources\*.
Example:
namespace App\Http\Resources;
use Laranail\DbConsole\Http\Resources\DatabaseResource as OriginalDatabaseResource;
class DatabaseResource extends OriginalDatabaseResource {
public function toArray($request) {
$array = parent::toArray($request);
$array['custom_field'] = 'value';
return $array;
}
}
Event Customization
Override default event behavior by binding to events in EventServiceProvider:
public function boot() {
\Laranail\DbConsole\Events\DatabaseCreated::dispatch(
$database
)->listen(function ($event) {
// Custom logic (e.g., notify Slack)
});
}
Multi-Tenancy
Use the tenant field in the users table to scope operations to specific tenants:
$user = \Laranail\DbConsole\Models\User::where('tenant', $tenantId)->first();
How can I help you explore Laravel packages today?