Skip to content

Instantly share code, notes, and snippets.

@sschlein
Created February 21, 2017 08:17
Show Gist options
  • Save sschlein/a5c17edd1a2a7f8a7d4dc3cf48b928aa to your computer and use it in GitHub Desktop.
Save sschlein/a5c17edd1a2a7f8a7d4dc3cf48b928aa to your computer and use it in GitHub Desktop.
DB Command for Laravel Valet
<?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');
@GerardKetuma
Copy link

Changed line 13 to accommodate root logins that have passwords set.
if($error = CommandLine::run('mysql -p -uroot -e "create database '.$name.'"')) {

@assoft
Copy link

assoft commented Jun 13, 2021

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