Last active
May 15, 2024 05:48
-
-
Save calebporzio/20b7d71b8b2690c788f28070f00edcbc to your computer and use it in GitHub Desktop.
An artisan command for opening the project's database in TablePlus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
@jimbojsb how did you discover the query parameters you mentioned in your blog? I am wondering if there are similar ones to setup a connection over SSH?