Last active
September 25, 2023 19:39
-
-
Save kmuenkel/c413ba5dcd1ab0a4540c3a0d15c0cf0d to your computer and use it in GitHub Desktop.
Table support generator aggragate
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
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Support\Str; | |
use Illuminate\Console\Command; | |
use Illuminate\Support\Facades\Artisan; | |
class GenerateTableSupportCommand extends Command | |
{ | |
protected $signature = "make:table {tables} {--connection=}"; | |
public function handle() | |
{ | |
$tables = explode(',', $this->argument('tables')); | |
// https://github.com/kitloong/laravel-migrations-generator | |
if ($this->option('connection')) { | |
Artisan::call('migrate:generate', ['--tables' => implode('.', $tables), '--connection' => $this->option('connection')]); | |
config(['database.connections.' . $this->option('connection') => 'database.connections.' . config('database.default')]); | |
} | |
Artisan::call('migrate:generate', ['--tables' => implode(',', $tables)]); | |
Artisan::call('migrate'); | |
// https://github.com/reliese/laravel | |
array_walk($tables, fn (string $table) => Artisan::call('code:models', ['--table' => $table])); | |
$namespace = config('models.*.namespace'); | |
// https://github.com/TheDoctor0/laravel-factory-generator | |
$modelNames = array_map(fn (string $table) => $namespace . '\\'. Str::singular(Str::studly($table)), $tables); | |
Artisan::call('generate:factory', ['model' => $modelNames]); | |
// https://github.com/orangehill/iseed | |
Artisan::call('iseed', ['tables' => implode(',', $tables)]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment