Skip to content

Commit fdc89b8

Browse files
committed
fixes: from table generation fixes
1 parent 3e7e107 commit fdc89b8

File tree

3 files changed

+109
-81
lines changed

3 files changed

+109
-81
lines changed

samples/fields_sample.json

+105-74
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,160 @@
11
[
22
{
33
"name": "id",
4-
"dbType": "increments",
5-
"htmlType": "",
6-
"validations": "",
4+
"dbType": "id",
5+
"htmlType": null,
6+
"validations": null,
77
"searchable": false,
88
"fillable": false,
99
"primary": true,
1010
"inForm": false,
1111
"inIndex": false,
1212
"inView": false
1313
},
14+
{
15+
"name": "user_id",
16+
"dbType": "foreignId:constrained",
17+
"htmlType": "number",
18+
"relation": "mt1,User,user_id,id",
19+
"validations": "required|min:1",
20+
"searchable": false,
21+
"fillable": true,
22+
"primary": false,
23+
"inForm": true,
24+
"inIndex": true,
25+
"inView": true
26+
},
1427
{
1528
"name": "title",
1629
"dbType": "string",
1730
"htmlType": "text",
1831
"validations": "required",
19-
"searchable": true
20-
},
21-
{
22-
"name": "post_date",
23-
"dbType": "dateTime",
24-
"htmlType": "date",
25-
"searchable": true
32+
"searchable": true,
33+
"fillable": true,
34+
"primary": false,
35+
"inForm": true,
36+
"inIndex": true,
37+
"inView": true
2638
},
2739
{
2840
"name": "body",
2941
"dbType": "text",
30-
"htmlType": "textarea"
42+
"htmlType": "textarea",
43+
"validations": "",
44+
"searchable": true,
45+
"fillable": true,
46+
"primary": false,
47+
"inForm": true,
48+
"inIndex": true,
49+
"inView": true
3150
},
3251
{
33-
"name": "password",
34-
"dbType": "string",
35-
"htmlType": "password",
52+
"name": "is_featured",
53+
"dbType": "boolean",
54+
"htmlType": "boolean",
55+
"validations": "",
3656
"searchable": false,
37-
"inForm": false,
38-
"inIndex": false,
39-
"inView": false
57+
"fillable": true,
58+
"primary": false,
59+
"inForm": true,
60+
"inIndex": true,
61+
"inView": true
4062
},
4163
{
42-
"name": "token",
43-
"dbType": "string",
44-
"htmlType": "hidden",
64+
"name": "is_enabled",
65+
"dbType": "boolean",
66+
"htmlType": "checkbox",
67+
"validations": "",
4568
"searchable": false,
46-
"inForm": false,
47-
"inIndex": false,
48-
"inView": false
49-
},
50-
{
51-
"name": "email",
52-
"dbType": "string",
53-
"htmlType": "email",
54-
"searchable": true
69+
"fillable": true,
70+
"primary": false,
71+
"inForm": true,
72+
"inIndex": true,
73+
"inView": true
5574
},
5675
{
57-
"name": "author_gender",
58-
"dbType": "integer",
59-
"htmlType": "radio,Male:1,Female:0"
76+
"name": "published_at",
77+
"dbType": "date",
78+
"htmlType": "date",
79+
"validations": "",
80+
"searchable": false,
81+
"fillable": true,
82+
"primary": false,
83+
"inForm": true,
84+
"inIndex": true,
85+
"inView": true
6086
},
6187
{
62-
"name": "post_type",
88+
"name": "password",
6389
"dbType": "string",
64-
"htmlType": "radio,Public,Private",
65-
"searchable": true
90+
"htmlType": "password",
91+
"validations": "",
92+
"searchable": false,
93+
"fillable": true,
94+
"primary": false,
95+
"inForm": true,
96+
"inIndex": true,
97+
"inView": true
6698
},
6799
{
68-
"name": "post_visits",
100+
"name": "post_type",
69101
"dbType": "integer",
70-
"htmlType": "number"
71-
},
72-
{
73-
"name": "category",
74-
"dbType": "string",
75-
"htmlType": "select,Technology,LifeStyle,Education,Games",
76-
"searchable": true
77-
},
78-
{
79-
"name": "category_short",
80-
"dbType": "string",
81-
"htmlType": "select,Technology:tech,LifeStyle:ls,Education:edu,Games:game"
82-
},
83-
{
84-
"name": "is_private",
85-
"dbType": "boolean",
86-
"htmlType": "checkbox,1"
87-
},
88-
{
89-
"name": "writer_id",
90-
"dbType": "integer:unsigned:default,0:foreign,writers,id",
91-
"htmlType": "text",
92-
"relation": "mt1,Writer,writer_id,id"
93-
},
94-
{
95-
"type": "relation",
96-
"relation": "1tm,Comment"
102+
"htmlType": "radio:Blog:1,Event:2,Guest:3",
103+
"validations": "",
104+
"searchable": false,
105+
"fillable": true,
106+
"primary": false,
107+
"inForm": true,
108+
"inIndex": true,
109+
"inView": true
97110
},
98111
{
99-
"type": "relation",
100-
"relation": "1tm,User:customRelationName,user_id,id"
112+
"name": "status",
113+
"dbType": "integer",
114+
"htmlType": "select:Draft:1,Published:2,Archived:3",
115+
"validations": "",
116+
"searchable": false,
117+
"fillable": true,
118+
"primary": false,
119+
"inForm": true,
120+
"inIndex": true,
121+
"inView": true
101122
},
102123
{
103-
"name": "users",
104-
"type": "relation",
105-
"relation": "mtm,Role,user_roles,user_id,role_id"
124+
"name": "created_by",
125+
"dbType": "unsignedBigInteger:foreign,users,id",
126+
"htmlType": "number",
127+
"relation": "mt1,User,user_id,id",
128+
"validations": "required|min:1",
129+
"searchable": false,
130+
"fillable": true,
131+
"primary": false,
132+
"inForm": true,
133+
"inIndex": true,
134+
"inView": true
106135
},
107136
{
108137
"name": "created_at",
109138
"dbType": "timestamp",
110-
"htmlType": "",
111-
"validations": "",
139+
"htmlType": null,
140+
"validations": null,
112141
"searchable": false,
113142
"fillable": false,
114143
"primary": false,
115144
"inForm": false,
116-
"inIndex": false
145+
"inIndex": false,
146+
"inView": true
117147
},
118148
{
119149
"name": "updated_at",
120150
"dbType": "timestamp",
121-
"htmlType": "",
122-
"validations": "",
151+
"htmlType": null,
152+
"validations": null,
123153
"searchable": false,
124154
"fillable": false,
125155
"primary": false,
126156
"inForm": false,
127-
"inIndex": false
157+
"inIndex": false,
158+
"inView": true
128159
}
129160
]

src/Commands/BaseCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public function getOptions()
280280
['jsonFromGUI', null, InputOption::VALUE_REQUIRED, 'Direct Json string while using GUI interface'],
281281
['plural', null, InputOption::VALUE_REQUIRED, 'Plural Model name'],
282282
['table', null, InputOption::VALUE_REQUIRED, 'Table Name'],
283-
['fromTable', null, InputOption::VALUE_REQUIRED, 'Generate from existing table'],
283+
['fromTable', null, InputOption::VALUE_NONE, 'Generate from existing table'],
284284
['ignoreFields', null, InputOption::VALUE_REQUIRED, 'Ignore fields while generating from table'],
285285
['primary', null, InputOption::VALUE_REQUIRED, 'Custom primary key'],
286286
['prefix', null, InputOption::VALUE_REQUIRED, 'Prefix for all files'],

src/Utils/TableFieldsGenerator.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function prepareFieldsFromTable()
114114
break;
115115
case 'boolean':
116116
$name = Str::title(str_replace('_', ' ', $column->getName()));
117-
$field = $this->generateField($column, 'boolean', 'checkbox,1');
117+
$field = $this->generateField($column, 'boolean', 'checkbox');
118118
break;
119119
case 'datetime':
120120
$field = $this->generateField($column, 'datetime', 'date');
@@ -134,9 +134,6 @@ public function prepareFieldsFromTable()
134134
case 'float':
135135
$field = $this->generateNumberInput($column, 'float');
136136
break;
137-
case 'string':
138-
$field = $this->generateField($column, 'string', 'text');
139-
break;
140137
case 'text':
141138
$field = $this->generateField($column, 'text', 'textarea');
142139
break;
@@ -156,8 +153,8 @@ public function prepareFieldsFromTable()
156153
$field->inIndex = false;
157154
$field->inView = false;
158155
}
159-
$field->isNotNull = (bool) $column->getNotNull();
160-
$field->description = $column->getComment(); // get comments from table
156+
$field->isNotNull = $column->getNotNull();
157+
$field->description = $column->getComment() ?? ''; // get comments from table
161158

162159
$this->fields[] = $field;
163160
}

0 commit comments

Comments
 (0)