Created
July 6, 2022 11:41
-
-
Save chengkangzai/ec21c42442fbf0fff75c5d7241ea81c9 to your computer and use it in GitHub Desktop.
Generate Data Definition for academic purpose
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
public function index() | |
{ | |
$tables = DB::select('SHOW TABLES'); | |
$defs = collect($tables) | |
->pluck('Tables_in_' . env('DB_DATABASE')) | |
->map(function ($table) { | |
$data = DB::select('SELECT * FROM ' . $table . ' LIMIT 1'); | |
return [ | |
'table' => $table, | |
'columns' => DB::select('SHOW COLUMNS FROM ' . $table), | |
'data' => $data[0] ?? null, | |
]; | |
}); | |
return view('uml', compact('defs')); | |
} | |
--- | |
@foreach($defs as $def) | |
<h3>{{$def['table']}}</h3> | |
<table> | |
<thead> | |
<tr> | |
<td>Field</td> | |
<td>Type</td> | |
<td>NULL</td> | |
<td>Key</td> | |
<td>Default</td> | |
<td>Extras</td> | |
<td>Example</td> | |
</tr> | |
</thead> | |
<tbody> | |
@foreach($def['columns'] as $column) | |
<tr> | |
<td>{{$column->Field}}</td> | |
<td>{{$column->Type}}</td> | |
<td>{{$column->Null}}</td> | |
<td>{{$column->Key}}</td> | |
<td>{{$column->Default}}</td> | |
<td>{{$column->Extra}}</td> | |
<td>{{$def['data']?->{$column->Field} ?? 'NULL' }}</td> | |
</tr> | |
</tbody> | |
@endforeach | |
</table> | |
@endforeach |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment