-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabaseViewer.php
54 lines (50 loc) · 1.14 KB
/
DatabaseViewer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace LaraToolbox\DatabaseViewer;
class DatabaseViewer
{
/**
* Gets table list
*
* @return \Illuminate\Support\Collection
*/
public function getTables()
{
return collect(\DB::select('SHOW TABLES'))
->map(function ($table) {
return current($table);
});
}
/**
* Get table definition
*
* @param String $table
* @return \Illuminate\Support\Collection
*/
public function getTableDefinition($table)
{
/**
* [{
* +"Field": "id",
* +"Type": "bigint unsigned",
* +"Null": "NO",
* +"Key": "PRI",
* +"Default": null,
* +"Extra": "auto_increment",
* }]
*/
return collect(\DB::select(sprintf('DESCRIBE %s', $table)));
}
/**
* Get column names
*
* @param string $table
* @return \Illuminate\Support\Collection
*/
public function getColumns($table)
{
return $this->getTableDefinition($table)
->map(function ($item) {
return $item->Field;
});
}
}