Last active
June 18, 2018 23:36
-
-
Save zabaala/675025ae03c217558df30e6fa742954d to your computer and use it in GitHub Desktop.
A desc table command for artisans
This file contains hidden or 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 | |
namespace App\Commands; | |
use Illuminate\Console\Command; | |
class DescTableCommand extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'db:desc {table : Table name}'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Desc a database table'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
$table = $this->argument('table'); | |
$headers = ['Field', 'Type', 'Null', 'Key', 'Default', 'Extra']; | |
$desc = \DB::select("desc ${table};"); | |
$obj = []; | |
for ($i = 0; $i < count($desc); $i++) { | |
$obj[$i] = (Array)$desc[$i]; | |
} | |
$this->table($headers, $obj); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
Result