1
1
<?php
2
2
3
- namespace LaraSupport ;
3
+ namespace LaraSupport \ Facades ;
4
4
5
- use Illuminate \Support \Facades \DB ;
5
+ use Illuminate \Support \Facades \Facade ;
6
6
7
- class LaraDB
7
+ class LaraDB extends Facade
8
8
{
9
9
/**
10
- * @return array
10
+ * Get the registered name of the component.
11
+ *
12
+ * @return string
11
13
*/
12
- public static function getTables ()
14
+ protected static function getFacadeAccessor ()
13
15
{
14
- $ tablesInDb = DB ::select ('SHOW TABLES ' );
15
- $ db = "Tables_in_ " .env ('DB_DATABASE ' );
16
- $ tables = [];
17
-
18
- foreach ($ tablesInDb as $ table ){
19
- $ tables [] = $ table ->{$ db };
20
- }
21
-
22
- return $ tables ;
23
- }
24
-
25
- /**
26
- * @param $table
27
- * @return array
28
- */
29
- public static function getColumnsFullInfo ($ table )
30
- {
31
- $ columns = DB ::select ('show columns from ' . $ table );
32
- $ columnsInfo = [];
33
-
34
- foreach ($ columns as $ column ) {
35
- $ columnsInfo [$ column ->Field ] = [
36
- 'type ' => Str::before ($ column ->Type , '( ' ),
37
- 'is_nullable ' => $ column ->Null ? true : false ,
38
- 'default ' => $ column ->Default ,
39
- 'extra ' => $ column ->Extra ,
40
- 'unsigned ' => str_contains ($ column ->Type , 'unsigned ' ) ? true : false ,
41
- 'full_info ' => $ column ->Type ,
42
- ];
43
- if (Str::between ($ column ->Type , '( ' , ') ' ) != $ column ->Type ) {
44
- $ columnsInfo [$ column ->Field ]['length ' ] = Str::between ($ column ->Type , '( ' , ') ' );
45
- }
46
- }
47
-
48
- return $ columnsInfo ;
16
+ return 'lara-db ' ;
49
17
}
50
-
51
- /**
52
- * @return array
53
- */
54
- public static function getDBStructure ()
55
- {
56
- $ query = sprintf ("SELECT * FROM information_schema.columns WHERE table_schema ='%s' " , env ('DB_DATABASE ' ));
57
- $ dbStructures = DB ::select ($ query );
58
- $ tables = [];
59
-
60
- foreach ($ dbStructures as $ dbStructure ) {
61
- if ($ dbStructure ->DATA_TYPE == 'int ' ) {
62
- }
63
- $ tables [$ dbStructure ->TABLE_NAME ][$ dbStructure ->COLUMN_NAME ] = [
64
- 'type ' => $ dbStructure ->DATA_TYPE ,
65
- 'is_nullable ' => $ dbStructure ->IS_NULLABLE == 'YES ' ? true : false ,
66
- 'default ' => $ dbStructure ->COLUMN_DEFAULT ,
67
- 'extra ' => $ dbStructure ->EXTRA ,
68
- 'unsigned ' => str_contains ($ dbStructure ->COLUMN_TYPE , 'unsigned ' ) ? true : false ,
69
- 'column_type ' => $ dbStructure ->COLUMN_TYPE ,
70
- ];
71
- if ($ dbStructure ->CHARACTER_MAXIMUM_LENGTH ) {
72
- $ tables [$ dbStructure ->TABLE_NAME ][$ dbStructure ->COLUMN_NAME ]['length ' ] = $ dbStructure ->CHARACTER_MAXIMUM_LENGTH ;
73
- }
74
- }
75
-
76
- return $ tables ;
77
- }
78
-
79
18
}
0 commit comments