From b62458ee43af30289fb9ff4dcf345d25551c50d0 Mon Sep 17 00:00:00 2001 From: ShibuyaKosuke Date: Sat, 29 May 2021 23:27:41 +0900 Subject: [PATCH] mod --- src/Console/RuleExportCommend.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Console/RuleExportCommend.php b/src/Console/RuleExportCommend.php index 9391fa9..e8faf85 100644 --- a/src/Console/RuleExportCommend.php +++ b/src/Console/RuleExportCommend.php @@ -7,7 +7,6 @@ use ShibuyaKosuke\LaravelDdlExport\Facades\CreateView; use ShibuyaKosuke\LaravelDdlExport\Facades\Table; use ShibuyaKosuke\LaravelDdlExport\Facades\Type; -use ShibuyaKosuke\LaravelDdlExport\Helpers\Arr; use ShibuyaKosuke\LaravelDdlExport\Models\Contracts\ColumnInterface; use ShibuyaKosuke\LaravelDdlExport\Models\Contracts\ConstraintInterface; use ShibuyaKosuke\LaravelDdlExport\Models\Contracts\TableInterface; @@ -42,7 +41,7 @@ public function handle(): void $response = Table::all()->mapWithKeys(function (TableInterface $table) { return [ $table->name => $table->columns - ->mapWithKeys(static function (ColumnInterface $column) { + ->map(static function (ColumnInterface $column) { /** @var ConstraintInterface $constraint */ $foreign = ($constraint = $column->foreign) ? sprintf( @@ -64,16 +63,29 @@ public function handle(): void if ($foreign) { $rules[] = $foreign; } - return [$column->name => $rules]; + $rules = array_map(function ($item) { + return "'" . $item . "'"; + }, $rules); + return [sprintf("'%s'", $column->name) . ' => [' . implode(', ', $rules) . '],']; }) ]; })->toArray(); CreateView::down(); + $res = '[' . PHP_EOL; + foreach ($response as $tableName => $columns) { + $res .= " '" . $tableName . '\' => [' . PHP_EOL; + foreach ($columns as $column) { + $res .= ' ' . $column[0] . PHP_EOL; + } + $res .= ' ],' . PHP_EOL; + } + $res .= ']'; + File::put( config_path('rules.php'), - sprintf("