Skip to content

Instantly share code, notes, and snippets.

@zabaala
Last active June 18, 2018 23:36
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zabaala/675025ae03c217558df30e6fa742954d to your computer and use it in GitHub Desktop.
Save zabaala/675025ae03c217558df30e6fa742954d to your computer and use it in GitHub Desktop.
A desc table command for artisans
<?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);
}
}
@zabaala
Copy link
Author

zabaala commented Aug 23, 2017

Usage:

php artisan db:desc users

Result

screen shot 2017-08-23 at 12 04 11 pm

@tdsereno
Copy link

Nice

@zabaala
Copy link
Author

zabaala commented Aug 23, 2017

@tdsereno Thanks a lot!

@ali-syria
Copy link

Thanks ,Nice Work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment