3
3
namespace AndreaCivita \ApiCrudGenerator \Commands ;
4
4
5
5
use AndreaCivita \ApiCrudGenerator \Core \Generator ;
6
+ use Doctrine \DBAL \Driver \PDOException ;
6
7
use Illuminate \Console \Command ;
7
8
use Illuminate \Database \QueryException ;
8
9
use Illuminate \Support \Facades \DB ;
@@ -53,12 +54,6 @@ class ApiCrudGenerator extends Command
53
54
*/
54
55
protected $ passport ;
55
56
56
- /**
57
- * Db support istance
58
- *
59
- * @var \Illuminate\Support\Facades\DB $db
60
- */
61
- protected $ db ;
62
57
63
58
/**
64
59
* Schema support instance
@@ -72,15 +67,13 @@ class ApiCrudGenerator extends Command
72
67
*
73
68
* @param Generator $generator
74
69
* @param Str $str
75
- * @param DB $db
76
70
* @param Schema $schema
77
71
*/
78
- public function __construct (Generator $ generator , Str $ str , DB $ db , Schema $ schema )
72
+ public function __construct (Generator $ generator , Str $ str , Schema $ schema )
79
73
{
80
74
parent ::__construct ();
81
75
$ this ->generator = $ generator ;
82
76
$ this ->str = $ str ;
83
- $ this ->db = $ db ;
84
77
$ this ->schema = $ schema ;
85
78
}
86
79
@@ -117,6 +110,28 @@ public function handle()
117
110
}
118
111
119
112
113
+ /**
114
+ * Handle all-db generation
115
+ * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
116
+ */
117
+ protected function all ()
118
+ {
119
+ try {
120
+ $ tables = DB ::connection ()->getDoctrineSchemaManager ()->listTableNames ();
121
+ foreach ($ tables as $ table ) {
122
+ $ this ->comment ("Generating " . $ table . " CRUD " );
123
+ $ columns = Schema::getColumnListing ($ table );
124
+ $ name = ucwords ($ this ->str ->singular ($ table ));
125
+ in_array ('created_at ' , $ columns ) ? $ timestamps = true : $ timestamps = false ;
126
+ $ this ->generate ($ name , $ table , $ timestamps );
127
+ }
128
+ }
129
+ catch (QueryException $ exception ) {
130
+ $ this ->error ("Error: " . $ exception ->getMessage ());
131
+ }
132
+ }
133
+
134
+
120
135
/**
121
136
* Generate CRUD in interactive mode
122
137
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
@@ -176,25 +191,4 @@ protected function generate($name, $table, $timestamps)
176
191
$ this ->info ("Generated Test! " );
177
192
}
178
193
179
-
180
- /**
181
- * Handle all-db generation
182
- * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
183
- */
184
- protected function all ()
185
- {
186
- try {
187
- $ tables = DB ::select ('SHOW TABLES ' );
188
- foreach ($ tables as $ table ) {
189
- $ this ->comment ("Generating " . $ table ->Tables_in_crud . " CRUD " );
190
- $ columns = Schema::getColumnListing ($ table ->Tables_in_crud );
191
- $ table = $ table ->Tables_in_crud ;
192
- $ name = ucwords ($ this ->str ->singular ($ table ));
193
- in_array ('created_at ' , $ columns ) ? $ timestamps = true : $ timestamps = false ;
194
- $ this ->generate ($ name , $ table , $ timestamps );
195
- }
196
- } catch (QueryException $ exception ) {
197
- $ this ->error ("Error: " . $ exception ->getMessage ());
198
- }
199
- }
200
194
}
0 commit comments