Created
February 21, 2017 08:17
-
-
Save sschlein/a5c17edd1a2a7f8a7d4dc3cf48b928aa to your computer and use it in GitHub Desktop.
DB Command for Laravel Valet
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 | |
// Put this file in your ~/.valet/Extensions directory! | |
/** | |
* Create a new database on your local machine. | |
*/ | |
$app->command('db [name]', function ($name) { | |
if(!$name) { | |
warning('Please specify a database name'); | |
return; | |
} | |
if($error = CommandLine::run('mysql -uroot -e "create database '.$name.'"')) { | |
warning($error); | |
} else { | |
info('The database '.$name.' has been created'); | |
} | |
})->descriptions('Create a new database'); | |
Deprecated: Non-static method Valet\CommandLine::run() should not be called statically in /Users/assoft/.config/valet/Extensions/make_db.php on line 16
Update:
$command = new CommandLine();
if (!$name) {
warning('Please specify a database name');
return;
}
if ($error = $command->run('mysql -uroot -e "create database ' . $name . '"')) {
warning($error);
} else {
info('The database ' . $name . ' has been created');
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Changed line 13 to accommodate root logins that have passwords set.
if($error = CommandLine::run('mysql -p -uroot -e "create database '.$name.'"')) {