Skip to content

Instantly share code, notes, and snippets.

@ziadoz
Forked from calebporzio/artisan_db_open.php
Created February 4, 2020 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ziadoz/897d18ac3a6f7d9c6f95e728dae0f419 to your computer and use it in GitHub Desktop.
Save ziadoz/897d18ac3a6f7d9c6f95e728dae0f419 to your computer and use it in GitHub Desktop.
An artisan command for opening the project's database in TablePlus
<?php
Artisan::command('db:open {connection?}', function ($connection = null) {
if (! file_exists('/Applications/TablePlus.app')) {
$this->warn('This command uses TablePlus, are you sure it\'s installed?');
$this->line("Install here: https://tableplus.com/\n");
}
$driver = $connection ?: config('database.default');
$host = config("database.connections.{$driver}.host");
$user = config("database.connections.{$driver}.username");
$password = config("database.connections.{$driver}.password");
$database = config("database.connections.{$driver}.database");
if ($driver === 'sqlite') {
exec("open {$database}");
} else {
exec("open {$driver}://{$user}:{$password}@{$host}/{$database}");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment