Skip to content

Commit a7cfa94

Browse files
committed
Adds column_definitions key to the config for super flexible default settings
1 parent 32badcf commit a7cfa94

17 files changed

+363
-561
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "crestapps/laravel-code-generator",
33
"license": "MIT",
44
"description": "A clean code generator for Laravel framework that will save you time! This awesome tool will help you generate resources like views, controllers, routes, migrations, languages or request-forms! It is extremely flexible and customizable to cover many use cases. It is shipped with cross-browsers compatible template, along with a client-side validation to modernize your application.",
5-
"version": "v2.0.0",
5+
"version": "v2.1.0",
66
"keywords": [
77
"laravel","crud","crud generator",
88
"laravel crud generator","laravel crud builder",

config/.php_cs.cache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"php":"7.1.1","version":"2.3.1:v2.3.1#d5257f7433bb490299c4f300d95598fd911a8ab0","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true},"hashes":{"codegenerator.php":1292351656}}
1+
{"php":"7.1.1","version":"2.3.1:v2.3.1#d5257f7433bb490299c4f300d95598fd911a8ab0","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true},"hashes":{"codegenerator.php":2111909562}}

config/codegenerator.php

Lines changed: 154 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
|--------------------------------------------------------------------------
99
|
1010
| Here you change the stub templates to use when generating code.
11-
| You can duplicate the "default" template folder
12-
| and call it what ever template your like "ex. skyblue".
11+
| You can duplicate the 'default' template folder
12+
| and call it what ever template your like 'ex. skyblue'.
1313
| Now, you can change the stubs to have your own templates generated.
1414
|
15-
|
15+
|
1616
| IMPORTANT: It is not recomended to modify the default template, rather create a new template.
17-
| If you modify the default template and then executed "php artisan vendor:publish" command,
17+
| If you modify the default template and then executed 'php artisan vendor:publish' command,
1818
| it will override the default template causing you to lose your modification.
1919
|
2020
*/
@@ -36,7 +36,7 @@
3636
|--------------------------------------------------------------------------
3737
|
3838
| If you want to generate code by using laravel-collective, you must first
39-
| install the package. Then add the tamplate name that should be using
39+
| install the package. Then add the tamplate name that should be using
4040
| Laravel-Collective extensions when generating code.
4141
*/
4242
'laravel_collective_templates' => [
@@ -54,7 +54,7 @@
5454

5555
/*
5656
|--------------------------------------------------------------------------
57-
| The default format for the datetime output
57+
| The default output format for datetime fields.
5858
|--------------------------------------------------------------------------
5959
|
6060
|
@@ -63,7 +63,7 @@
6363

6464
/*
6565
|--------------------------------------------------------------------------
66-
| The default path of where the field json files are located
66+
| The default path of where the field json files are located.
6767
|--------------------------------------------------------------------------
6868
|
6969
| In this path, you can create json file to import the fields from.
@@ -113,128 +113,174 @@
113113
*/
114114
'common_header_patterns' => ['title','name','label','header'],
115115

116-
/*
117-
|--------------------------------------------------------------------------
118-
| Key phrases that are will be used to determine if a field should be a primary key.
119-
|--------------------------------------------------------------------------
120-
*/
121-
'common_id_patterns' => ['id'],
122-
123-
/*
124-
|--------------------------------------------------------------------------
125-
| Patterns to use to determine "datetime" fields if date-type is not provided
126-
|--------------------------------------------------------------------------
127-
|
128-
| If the date-type for a field is not, the codegenerator scanns the field's name
129-
| for a matching pattern. If the name matches any of the set pattern, the the
130-
| field's type will automaticly be set to datetime.
131-
|
132-
*/
133-
'common_datetime_patterns' => ['*_at','*_date'],
134-
135-
/*
136-
|--------------------------------------------------------------------------
137-
| Patterns to use to determine "boolean" fields if date-type is not provided
138-
|--------------------------------------------------------------------------
139-
|
140-
| If the date-type for a field is not, the codegenerator scanns the field's name
141-
| for a matching pattern. If the name matches any of the set pattern, the the
142-
| field's type will automaticly be set to boolean.
143-
|
144-
*/
145-
'common_boolean_patterns' => ['is_*','has_*'],
146-
147116
/*
148117
|--------------------------------------------------------------------------
149118
| Key phrases that are will be used to determine if a field should have a relation.
150119
|--------------------------------------------------------------------------
151120
|
152121
| When creating resources from existing database, the codegenerator scans
153-
| the field's name for a mattching pattern. When found, these field are considred
122+
| the field's name for a mattching pattern. When found, these field are considred
154123
| foreign keys even if the database does not have a foreign constraints.
155124
| Here you can specify patterns to help the generator understand your
156125
| database naming convension.
157126
|
158127
*/
159128
'common_key_patterns' => ['*_id','*_by'],
160-
129+
161130
/*
162131
|--------------------------------------------------------------------------
163-
| Common foreign keys definitions
132+
| Patterns to use to pre-set field's properties.
164133
|--------------------------------------------------------------------------
165134
|
166-
| The code generator uses "common_key_patterns" array to scan the field name
167-
| for matching patterns to determine if a field should be considred foreign key.
168-
| "common_foreign_keys" allows you to set global configuration for common foreign key.
169-
| Each key in the array represents the field name. The value is an array of definitions
170-
| to use. Here is description of the definition array
171-
|
172-
| "name" will be used to create the relation method's name.
173-
| "type" will be used to set the relation type
174-
| "params" the parameters to use for the "type" relation.
175-
| "field" the field on the foreign model to use as display name.
176-
| "on-create" sets a value to use when this model is created. If your using an authentication
177-
| system such as laravel build in authentication. you can automaticly set
178-
| the user Id who created the model by setting this value to 'Auth::Id();'.
179-
| "on-update" sets a value to use when this model is update.
135+
| To make constructing fields easy, the codegenerator scans the field's name
136+
| for a matching pattern. If the name matches any of the set pattern, the the
137+
| field's properties will be preset. defining pattern will save you from having
138+
| to re-define the properties for common fields.
180139
|
181140
*/
182-
183-
"common_foreign_keys" => [
184-
"owner_id" => [
185-
"name" => "owner",
186-
"type" => "belongsTo",
187-
"params" => [
188-
"App\\User",
189-
"owner_id"
190-
],
191-
"field" => "name",
192-
"on-store" => null,
193-
"on-update" => null,
141+
'common_definitions' => [
142+
[
143+
'match' => 'id',
144+
'set' => [
145+
'is-on-form' => false,
146+
'is-on-index' => false,
147+
'is-on-show' => false,
148+
'html-type' => 'hidden',
149+
'data-type' => 'integer',
150+
'is-primary' => true,
151+
'is-auto-increment' => true,
152+
'is-nullable' => false,
153+
'is-unsigned' => true,
154+
]
155+
],
156+
[
157+
'match' => ['*_id','*_by'],
158+
'set' => [
159+
'data-type' => 'integer',
160+
'html-type' => 'select',
161+
'is-nullable' => false,
162+
'is-unsigned' => true,
163+
]
164+
],
165+
[
166+
'match' => ['*_at'],
167+
'set' => [
168+
'data-type' => 'dateTime'
169+
]
170+
],
171+
[
172+
'match' => ['created_at','updated_at','deleted_at'],
173+
'set' => [
174+
'data-type' => 'dateTime',
175+
'is-on-form' => false,
176+
'is-on-index' => false,
177+
'is-on-show' => true,
178+
]
179+
],
180+
[
181+
'match' => ['*_date'],
182+
'set' => [
183+
'data-type' => 'date',
184+
'date-format' => 'm/d/Y'
185+
]
186+
],
187+
[
188+
'match' => ['is_*','has_*'],
189+
'set' => [
190+
'data-type' => 'boolean',
191+
'html-type' => 'checkbox',
192+
'is-nullable' => false
193+
]
194+
],
195+
[
196+
'match' => 'owner_id',
197+
'set' => [
198+
'title' => 'Owner',
199+
'data-type' => 'integer',
200+
'foreign-relation' => [
201+
'name' => 'owner',
202+
'type' => 'belongsTo',
203+
'params' => [
204+
'App\\User',
205+
'owner_id'
206+
],
207+
'field' => 'name'
208+
],
209+
'on-store' => null,
210+
'on-update' => null
211+
]
194212
],
195-
"operator_id" => [
196-
"name" => "operator",
197-
"type" => "belongsTo",
198-
"params" => [
199-
"App\\User",
200-
"operator_id"
201-
],
202-
"field" => "name",
203-
"on-store" => null,
204-
"on-update" => null,
213+
[
214+
'match' => 'operator_id',
215+
'set' => [
216+
'title' => 'Operator',
217+
'data-type' => 'integer',
218+
'foreign-relation' => [
219+
'name' => 'operator',
220+
'type' => 'belongsTo',
221+
'params' => [
222+
'App\\User',
223+
'operator_id'
224+
],
225+
'field' => 'name'
226+
],
227+
'on-store' => null,
228+
'on-update' => null
229+
]
205230
],
206-
"author_id" => [
207-
"name" => "author",
208-
"type" => "belongsTo",
209-
"params" => [
210-
"App\\User",
211-
"author_id"
212-
],
213-
"field" => "name",
214-
"on-store" => null,
215-
"on-update" => null,
231+
[
232+
'match' => 'author_id',
233+
'set' => [
234+
'title' => 'Author',
235+
'data-type' => 'integer',
236+
'foreign-relation' => [
237+
'name' => 'author',
238+
'type' => 'belongsTo',
239+
'params' => [
240+
'App\\User',
241+
'author_id'
242+
],
243+
'field' => 'name'
244+
],
245+
'on-store' => null,
246+
'on-update' => null
247+
]
216248
],
217-
"created_by" => [
218-
"name" => "creator",
219-
"type" => "belongsTo",
220-
"params" => [
221-
"App\\User",
222-
"created_by"
223-
],
224-
"field" => "name",
225-
"on-store" => "Illuminate\Support\Facades\Auth::Id();",
226-
"on-update" => null,
249+
[
250+
'match' => 'created_by',
251+
'set' => [
252+
'title' => 'Creator',
253+
'data-type' => 'integer',
254+
'foreign-relation' => [
255+
'name' => 'creator',
256+
'type' => 'belongsTo',
257+
'params' => [
258+
'App\\User',
259+
'created_by'
260+
],
261+
'field' => 'name'
262+
],
263+
'on-store' => 'Illuminate\Support\Facades\Auth::Id();',
264+
'on-update' => null
265+
]
227266
],
228-
"updated_by" => [
229-
"name" => "updator",
230-
"type" => "belongsTo",
231-
"params" => [
232-
"App\\User",
233-
"created_by"
234-
],
235-
"field" => "name",
236-
"on-store" => null,
237-
"on-update" => "Illuminate\Support\Facades\Auth::Id();",
267+
[
268+
'match' => ['updated_by','modified_by'],
269+
'set' => [
270+
'title' => 'Updater',
271+
'data-type' => 'integer',
272+
'foreign-relation' => [
273+
'name' => 'updater',
274+
'type' => 'belongsTo',
275+
'params' => [
276+
'App\\User',
277+
'updated_by'
278+
],
279+
'field' => 'name'
280+
],
281+
'on-store' => null,
282+
'on-update' => 'Illuminate\Support\Facades\Auth::Id();'
283+
]
238284
]
239285
],
240286

@@ -300,7 +346,7 @@
300346

301347
/*
302348
|--------------------------------------------------------------------------
303-
| Eloquent method to html-type mapping
349+
| Eloquent method to html-type mapping.
304350
|--------------------------------------------------------------------------
305351
|
306352
| This is the mapping used to convert database-column into html field

src/Commands/CreateFieldsFileCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected function getFieldAsJson()
7474
return $field->toArray();
7575
}, $this->getFields());
7676

77-
return json_encode($fields, JSON_PRETTY_PRINT);
77+
return json_encode($fields, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
7878
}
7979

8080
/**

src/Commands/CreateMigrationCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ protected function addTimestamps(& $property, $without)
782782
protected function addSoftDelete(& $property, $withSoftDelete)
783783
{
784784
if ($withSoftDelete) {
785-
$property .= sprintf("%s()", $this->getPropertyBase('softDelete'));
785+
$property .= sprintf("%s()", $this->getPropertyBase('softDeletes'));
786786
$this->addFieldPropertyClousure($property);
787787
}
788788

src/Commands/FieldsFileAppendCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function handle()
5959
}
6060

6161
$existingFields = $this->mergeFields($file, $input);
62-
$string = json_encode($existingFields, JSON_PRETTY_PRINT);
62+
$string = json_encode($existingFields, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
6363

6464
$this->putContentInFile($file, $string)
6565
->info('New fields where appended to the file.');

src/Commands/FieldsFileCreateCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function handle()
5858
}
5959

6060
$fields = $this->getFields($input, $input->withoutPrimaryKey);
61-
$string = $this->getFieldAsJson($fields, JSON_PRETTY_PRINT);
61+
$string = $this->getFieldAsJson($fields, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
6262

6363
$this->createFile($file, $string)
6464
->info('New fields-file was crafted!');
@@ -152,7 +152,7 @@ protected function getFieldAsJson($fields)
152152
return $field->toArray();
153153
}, $fields);
154154

155-
return json_encode($rarField, JSON_PRETTY_PRINT);
155+
return json_encode($rarField, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
156156
}
157157

158158
/**

src/Commands/FieldsFileReduceCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function handle()
6262
return false;
6363
}
6464

65-
$string = json_encode($reducedFields, JSON_PRETTY_PRINT);
65+
$string = json_encode($reducedFields, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
6666

6767
$this->putContentInFile($file, $string)
6868
->info('Fields where removed from exising file');

0 commit comments

Comments
 (0)