Commit 339eaad4 authored by Stefan Hess's avatar Stefan Hess
Browse files

created composer package, added db:console command

parents
{
"name": "guapp/laravel-toolbox",
"description": "Toolbox for Laravel applications",
"require": {
"illuminate/console": "~5.1",
"illuminate/contracts": "~5.1",
"illuminate/support": "~5.1"
},
"authors": [
{
"name": "Stefan Hess",
"email": "stefan@hess.space"
}
],
"autoload": {
"psr-4": {
"Guapp\\LaravelToolbox\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Guapp\\LaravelToolbox\\ToolboxServiceProvider"
]
}
},
"config": {
"sort-packages": true
}
}
This diff is collapsed.
<?php
namespace Guapp\LaravelToolbox\Console;
use Illuminate\Console\Command;
use App\Models\User;
use Symfony\Component\Process\Process;
class DbConsoleCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'db:console';
/**
* The console command description.
*
* @var string
*/
protected $description = 'This command opens a MySQL console and logs in the database user.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$user = env("DB_USERNAME");
$pass = env("DB_PASSWORD");
$db = env("DB_DATABASE");
$command = "mysql -u $user -p$pass $db 1>&2";
exec($command);
}
}
<?php
namespace Guapp\LaravelToolbox;
use Illuminate\Support\ServiceProvider;
use Guapp\LaravelToolbox\Console\DbConsoleCommand;
class ToolboxServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('command.dbconsole', function () {
return new DbConsoleCommand;
});
$this->commands(['command.dbconsole']);
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return ['command.dbconsole'];
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment