feat: 支持已有表生成代码
This commit is contained in:
parent
3867be14b2
commit
c03213e7c3
28
modules/Common/Repository/Options/Schemas.php
Normal file
28
modules/Common/Repository/Options/Schemas.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Common\Repository\Options;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class Schemas implements OptionInterface
|
||||||
|
{
|
||||||
|
public function get(): array
|
||||||
|
{
|
||||||
|
$options = [];
|
||||||
|
|
||||||
|
$tablePrefix = DB::connection()->getTablePrefix();
|
||||||
|
|
||||||
|
foreach (Schema::getTables() as $table) {
|
||||||
|
$tableName = Str::of($table['name'])->remove($tablePrefix);
|
||||||
|
|
||||||
|
$options[] = [
|
||||||
|
'label' => $tableName . "\t\t\t\t" . $table['comment'],
|
||||||
|
'value' => $tableName,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
}
|
@ -48,6 +48,18 @@ class Schemas extends CatchModel
|
|||||||
*/
|
*/
|
||||||
public function storeBy(array $data): bool
|
public function storeBy(array $data): bool
|
||||||
{
|
{
|
||||||
|
// 从已有 schema 中选择
|
||||||
|
if (isset($data['schema_name'])) {
|
||||||
|
$columns = SchemaFacade::getColumnListing($data['schema_name']);
|
||||||
|
|
||||||
|
return parent::storeBy([
|
||||||
|
'module' => $data['module'],
|
||||||
|
'name' => $data['schema_name'],
|
||||||
|
'columns' => implode(',', $columns),
|
||||||
|
'is_soft_delete' => isset($columns['deleted_at']) ? Status::Enable : Status::Disable,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$schema = $data['schema'];
|
$schema = $data['schema'];
|
||||||
|
|
||||||
$structures = $data['structures'];
|
$structures = $data['structures'];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user