Skip to content

Commit 58e14e8

Browse files
authored
Dev (#25)
* Change model folder name * Add request comments * Generate resource * Generate resource controller * CHange model namespace * Fix generated message * Create test in correct folder and namespace * Generate factory * Fix variable naming * Test refactoring * Fix factory path * Fix test template * Overwrite test instead append * Revert "Merge pull request #7 from bastianjoel/master" This reverts commit ecfaa98, reversing changes made to 275df6f. * Revert "Merge pull request #7 from bastianjoel/master" This reverts commit ecfaa98, reversing changes made to 275df6f. * Update README.md * Complete refactor (#12) * Create CONTRIBUTING.MD * Use laravel filesystem * Fix cs * Update README.md * Fix bastianjoel pr errors Fixing truble into pull request * switched to STR str_plural * Removed unused dependencies * Fix timestamp not working * Refactoring PHPDoc & Added Str dependency Refactored PHPDoc and added dependency injection for \Illuminate\Support\String * Some style fix * Refactoring ApiCrudGenerator class Refactoring ApiCrudGenerator class for keeping number of methods under 10. This should help in fixing. Added Stub Class (Helper for parse & get stub) Added Generator Class (Helper for generating files) * Missing str dependency * Updated readme * Fix readme authors * Moved core class into Core * Fixed dependencies * Added unit tests * Added stub test and refactor laravel helpers * Deleted laravel_helpers * Fix generator * Another fix * Added test for generator * Added travis support * Fix * Fix travis * Passport integration (#16) * Fix test & added test secure * Added passport support * Fix styling * Secure routes * Fix testSecureRoot * Codecov + travis * Delete CODE_OF_CONDUCT.md * Fixed deprecated touch() call * Added Dependency Injection Refactored file with dependency injection for DB & Schema Facades * Fix documentation * Testing fix * Fixed --all bug * Delete LICENSE * Merge fixing-all branch to dev (#24) * Fixed all method * Removed $db support instance
1 parent 131871e commit 58e14e8

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

src/Commands/ApiCrudGenerator.php

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace AndreaCivita\ApiCrudGenerator\Commands;
44

55
use AndreaCivita\ApiCrudGenerator\Core\Generator;
6+
use Doctrine\DBAL\Driver\PDOException;
67
use Illuminate\Console\Command;
78
use Illuminate\Database\QueryException;
89
use Illuminate\Support\Facades\DB;
@@ -53,12 +54,6 @@ class ApiCrudGenerator extends Command
5354
*/
5455
protected $passport;
5556

56-
/**
57-
* Db support istance
58-
*
59-
* @var \Illuminate\Support\Facades\DB $db
60-
*/
61-
protected $db;
6257

6358
/**
6459
* Schema support instance
@@ -72,15 +67,13 @@ class ApiCrudGenerator extends Command
7267
*
7368
* @param Generator $generator
7469
* @param Str $str
75-
* @param DB $db
7670
* @param Schema $schema
7771
*/
78-
public function __construct(Generator $generator, Str $str, DB $db, Schema $schema)
72+
public function __construct(Generator $generator, Str $str, Schema $schema)
7973
{
8074
parent::__construct();
8175
$this->generator = $generator;
8276
$this->str = $str;
83-
$this->db = $db;
8477
$this->schema = $schema;
8578
}
8679

@@ -117,6 +110,28 @@ public function handle()
117110
}
118111

119112

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+
120135
/**
121136
* Generate CRUD in interactive mode
122137
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
@@ -176,25 +191,4 @@ protected function generate($name, $table, $timestamps)
176191
$this->info("Generated Test!");
177192
}
178193

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-
}
200194
}

0 commit comments

Comments
 (0)