Closed qcol closed 7 years ago
When running the above command in a fresh environment it works perfectly fine. I am suspecting something with your local environment. Either way you should not get that exception so I like to reproduce and trace it.
Can you please share the content of you /resources/codegenerator-files/asset_categories.json
and /config/codegenerator.php
files so I can reproduce the issue?
Sure:
[
{
"name": "id",
"labels": "Id",
"html-type": "hidden",
"css-class": "",
"options": {},
"html-value": null,
"validation": "",
"is-on-index": false,
"is-on-show": false,
"is-on-form": false,
"data-type": "int",
"data-type-params": [],
"data-value": null,
"is-index": false,
"is-unique": false,
"is-primary": true,
"comment": null,
"is-nullable": false,
"is-header": false,
"is-unsigned": true,
"is-auto-increment": true,
"is-inline-options": false,
"is-date": false,
"date-format": "",
"cast-as": "",
"placeholder": {},
"delimiter": "; ",
"range": [],
"foreign-relation": null,
"foreign-constraint": null,
"on-store": null,
"on-update": null
},
{
"name": "name",
"labels": {
"en": "Name",
"ar": "Name"
},
"html-type": "text",
"css-class": "",
"options": {},
"html-value": null,
"validation": "required|string|min:1|max:255",
"is-on-index": true,
"is-on-show": true,
"is-on-form": true,
"data-type": "string",
"data-type-params": [
255
],
"data-value": null,
"is-index": false,
"is-unique": false,
"is-primary": false,
"comment": null,
"is-nullable": false,
"is-header": true,
"is-unsigned": false,
"is-auto-increment": false,
"is-inline-options": false,
"is-date": false,
"date-format": "",
"cast-as": "",
"placeholder": {
"en": "Enter name here...",
"ar": "Enter name here..."
},
"delimiter": "; ",
"range": [],
"foreign-relation": null,
"foreign-constraint": null,
"on-store": null,
"on-update": null
},
{
"name": "description",
"labels": {
"en": "Description",
"ar": "Description"
},
"html-type": "textarea",
"css-class": "",
"options": {},
"html-value": null,
"validation": "string|min:1|max:1000",
"is-on-index": false,
"is-on-show": true,
"is-on-form": true,
"data-type": "string",
"data-type-params": [
1000
],
"data-value": null,
"is-index": false,
"is-unique": false,
"is-primary": false,
"comment": null,
"is-nullable": true,
"is-header": false,
"is-unsigned": false,
"is-auto-increment": false,
"is-inline-options": false,
"is-date": false,
"date-format": "",
"cast-as": "",
"placeholder": {},
"delimiter": "; ",
"range": [],
"foreign-relation": null,
"foreign-constraint": null,
"on-store": null,
"on-update": null
},
{
"name": "is_active",
"labels": {
"en": "Is Active",
"ar": "Is Active"
},
"html-type": "checkbox",
"css-class": "",
"options": {},
"html-value": null,
"validation": "boolean",
"is-on-index": true,
"is-on-show": true,
"is-on-form": true,
"data-type": "bool",
"data-type-params": [],
"data-value": null,
"is-index": false,
"is-unique": false,
"is-primary": false,
"comment": null,
"is-nullable": false,
"is-header": false,
"is-unsigned": false,
"is-auto-increment": false,
"is-inline-options": false,
"is-date": false,
"date-format": "",
"cast-as": "",
"placeholder": {},
"delimiter": "; ",
"range": [],
"foreign-relation": null,
"foreign-constraint": null,
"on-store": null,
"on-update": null
}
]
<?php
return [
/*
|--------------------------------------------------------------------------
| The default template to use.
|--------------------------------------------------------------------------
|
| Here you change the stub templates to use when generating code.
| You can duplicate the 'default' template folder
| and call it what ever template name you like 'ex. skyblue'.
| Now, you can change the stubs to have your own templates generated.
|
|
| IMPORTANT: It is not recomended to modify the default template, rather create a new template.
| If you modify the default template and then executed 'php artisan vendor:publish' command,
| will override your changes!
|
*/
'template' => 'default',
/*
|--------------------------------------------------------------------------
| The default path where the templates are located.
|--------------------------------------------------------------------------
|
| In this path, you can add more templates.
|
*/
'templates_path' => 'resources/codegenerator-templates',
/*
|--------------------------------------------------------------------------
| Array of templetes that should be generated with Laravel-Collective.
|--------------------------------------------------------------------------
|
| If you want to generate code by using laravel-collective, you must first
| install the package. Then add the tamplate name that should be using
| Laravel-Collective extensions when generating code.
|
|
*/
'laravel_collective_templates' => [
'default-collective'
],
/*
|--------------------------------------------------------------------------
| The default path of where the uploaded files lives.
|--------------------------------------------------------------------------
|
|
*/
'files_upload_path' => 'uploads',
/*
|--------------------------------------------------------------------------
| The default output format for datetime fields.
|--------------------------------------------------------------------------
|
| This output format can also be changed at the field level using the
| "date-format" property of the field.
|
*/
'datetime_out_format' => 'm/d/Y H:i A',
/*
|--------------------------------------------------------------------------
| The default path of where the json field files are located.
|--------------------------------------------------------------------------
|
| In this path, you can create json file to import the fields from.
|
*/
'fields_file_path' => 'resources/codegenerator-files',
/*
|--------------------------------------------------------------------------
| The default path of where the migrations will be generated into.
|--------------------------------------------------------------------------
*/
'migrations_path' => 'database/migrations',
/*
|--------------------------------------------------------------------------
| The default path of where the controllers will be generated into.
|--------------------------------------------------------------------------
*/
'form_requests_path' => 'Http/Requests',
/*
|--------------------------------------------------------------------------
| The default path of where the controllers will be generated into.
|--------------------------------------------------------------------------
*/
'controllers_path' => 'Http/Controllers',
/*
|--------------------------------------------------------------------------
| The default path of where the models will be generated into.
|--------------------------------------------------------------------------
*/
'models_path' => 'Models',
/*
|--------------------------------------------------------------------------
| The default path of where the languages will be generated into.
|--------------------------------------------------------------------------
*/
'languages_path' => 'resources/lang',
/*
|--------------------------------------------------------------------------
| The name of the default resources map file.
|--------------------------------------------------------------------------
*/
'default_mapper_file_name' => 'resources_map.json',
/*
|--------------------------------------------------------------------------
| Should the code generator auto manage resources mappers?
|--------------------------------------------------------------------------
*/
'auto_manage_resource_mapper' => true,
/*
|--------------------------------------------------------------------------
| Key phrases that are will be used to determine if a field name should be used for header.
|--------------------------------------------------------------------------
*/
'common_header_patterns' => ['title','name','label','header'],
/*
|--------------------------------------------------------------------------
| Patterns to use to generate the html placeholders.
|--------------------------------------------------------------------------
|
| When creating the fields, the code generator follows a pattern to generate
| placeholders for the html code. Here you can define which html-types should
| the generator create placeholder for. Also, you can define how would you like
| the text to read when no placeholder is assigned.
|
| The follwowing templates can be used to. assuming the field name is owner_name
| [% field_name %] <=> "owner name"
| [% field_name_sentence %] <=> "Owner name"
| [% field_name_plural %] <=> "owner names"
| [% field_name_plural_title %] <=> "Owner Names"
| [% field_name_snake %] <=> "owner_name"
| [% field_name_studly %] <=> "OwnerName"
| [% field_name_slug %] <=> "owner-name"
| [% field_name_kebab %] <=> "owner-name"
| [% field_name_title %] <=> "Owner Name"
| [% field_name_title_upper %] <=> "OWNER NAME"
| [% field_name_plural_variable %] <=> "ownerNames"
| [% field_name_singular_variable %] <=> "ownerName"
*/
'placeholder_by_html_type' =>
[
'text' => 'Enter [% field_name %] here...',
'number' => 'Enter [% field_name %] here...',
'password' => 'Enter [% field_name %] here...',
'email' => 'Enter [% field_name %] here...',
'select' => 'Select [% field_name %]',
],
/*
|--------------------------------------------------------------------------
| Key phrases that are will be used to determine if a field should have a relation.
|--------------------------------------------------------------------------
|
| When creating resources from existing database, the codegenerator scans
| the field's name for a mattching pattern. When found, these field are considred
| foreign keys even when the database does not have a foreign constraints.
| Here you can specify patterns to help the generator understand your
| database naming convension.
|
*/
'common_key_patterns' => ['*_id','*_by'],
/*
|--------------------------------------------------------------------------
| Patterns to use to pre-set field's properties.
|--------------------------------------------------------------------------
|
| To make constructing fields easy, the code-generator scans the field's name
| for a matching pattern. If the name matches any of these patterns, the
| field's properties will be set accordingly. Defining pattern will save
| you from having to re-define the properties for common fields.
|
*/
'common_definitions' => [
[
'match' => 'id',
'set' => [
'is-on-form' => false,
'is-on-index' => false,
'is-on-show' => false,
'html-type' => 'hidden',
'data-type' => 'integer',
'is-primary' => true,
'is-auto-increment' => true,
'is-nullable' => false,
'is-unsigned' => true,
]
],
[
'match' => ['title','name','label','header'],
'set' => [
'is-nullable' => false,
'data-type' => 'string',
'data-type-params' => [255],
]
],
[
'match' => ['*count*','total*','*number*','*age*'],
'set' => [
'html-type' => 'number'
]
],
[
'match' => ['description*','detail*','note*','message*'],
'set' => [
'is-on-index' => false,
'html-type' => 'textarea',
'data-type-params' => [1000],
]
],
[
'match' => ['picture','file','photo'],
'set' => [
'is-on-index' => false,
'html-type' => 'file',
]
],
[
'match' => ['*password*'],
'set' => [
'html-type' => 'password'
]
],
[
'match' => ['*email*'],
'set' => [
'html-type' => 'email'
]
],
[
'match' => ['*_id','*_by'],
'set' => [
'data-type' => 'integer',
'html-type' => 'select',
'is-nullable' => false,
'is-unsigned' => true,
'is-index' => true,
]
],
[
'match' => ['*_at'],
'set' => [
'data-type' => 'datetime',
]
],
[
'match' => ['created_at','updated_at','deleted_at'],
'set' => [
'data-type' => 'datetime',
'is-on-form' => false,
'is-on-index' => false,
'is-on-show' => true,
]
],
[
'match' => ['*_date'],
'set' => [
'data-type' => 'date',
'date-format' => 'm/d/Y',
]
],
[
'match' => ['is_*','has_*'],
'set' => [
'data-type' => 'boolean',
'html-type' => 'checkbox',
'is-nullable' => false,
]
],
[
'match' => 'created_by',
'set' => [
'title' => 'Creator',
'data-type' => 'integer',
'foreign-relation' => [
'name' => 'creator',
'type' => 'belongsTo',
'params' => [
'App\\User',
'created_by',
],
'field' => 'name',
],
'on-store' => 'Illuminate\Support\Facades\Auth::Id();',
]
],
[
'match' => ['updated_by','modified_by'],
'set' => [
'title' => 'Updater',
'data-type' => 'integer',
'foreign-relation' => [
'name' => 'updater',
'type' => 'belongsTo',
'params' => [
'App\\User',
'updated_by',
],
'field' => 'name',
],
'on-update' => 'Illuminate\Support\Facades\Auth::Id();',
]
]
],
/*
|--------------------------------------------------------------------------
| Non-Field base labels to be replaced in the views.
|--------------------------------------------------------------------------
|
| List of generic non-field labels to be replaced in the views.
| The "key" of the array is the value to be used in the locale files.
| The "text" key of the sub array, is the string to display in the view or add to the locale files.
| The "template" key of the sub array, is the string to be use in the view for replacement.
| The "in-function-with-collective" key of the sub array, tell the generator that,
| this string would be used in a function or not.
|
| The follwowing templates can be used. Assuming the model name is AssetCategory
| [% model_name %] <=> "asset category"
| [% model_name_sentence %] <=> "Asset category"
| [% model_name_plural %] <=> "asset categories"
| [% model_name_plural_title %] <=> "Asset Category"
| [% model_name_snake %] <=> "asset_category"
| [% model_name_studly %] <=> "AssetCategory"
| [% model_name_slug %] <=> "asset-category"
| [% model_name_kebab %] <=> "asset-category"
| [% model_name_title %] <=> "Asset Category"
| [% model_name_title_upper %] <=> "ASSET CATEGORY"
| [% model_name_plural_variable %] <=> "assetCategories"
| [% model_name_singular_variable %] <=> "assetCategory"
|
| ~Example
| Lets say we need to add a new template in our views that reads the following
| "Creating resources for ... was a breeze!"
| The following entry can be added to the below array
|
| 'custom_template_1' => [
| 'text' => 'Creating resources for [% model_name %] was a breeze!',
| 'template' => 'custom_template_example',
| ],
| Finally, add [% custom_template_example %] in the view where you want it to appear!
|
|
*/
'generic_view_labels' => [
'create' => [
'text' => 'Create New [% model_name_title %]',
'template' => 'create_model',
],
'delete' => [
'text' => 'Delete [% model_name_title %]',
'template' => 'delete_model',
'in-function-with-collective' => true,
],
'edit' => [
'text' => 'Edit [% model_name_title %]',
'template' => 'edit_model',
],
'show' => [
'text' => 'Show [% model_name_title %]',
'template' => 'show_model',
],
'show_all' => [
'text' => 'Show All [% model_name_title %]',
'template' => 'show_all_models',
],
'add' => [
'text' => 'Add',
'template' => 'add',
'in-function-with-collective' => true,
],
'update' => [
'text' => 'Update',
'template' => 'update',
'in-function-with-collective' => true,
],
'confirm_delete' => [
'text' => 'Delete [% model_name_title %]?',
'template' => 'confirm_delete',
'in-function-with-collective' => true,
],
'none_available' => [
'text' => 'No [% model_name_plural_title %] Available!',
'template' => 'no_models_available',
],
'model_plural' => [
'text' => '[% model_name_plural_title %]',
'template' => 'model_plural',
],
'model_was_added' => [
'text' => '[% model_name_title %] was successfully added!',
'template' => 'model_was_added',
],
'model_was_updated' => [
'text' => '[% model_name_title %] was successfully updated!',
'template' => 'model_was_updated',
],
'model_was_deleted' => [
'text' => '[% model_name_title %] was successfully deleted!',
'template' => 'model_was_deleted',
],
'unexpected_error' => [
'text' => 'Unexpected error occurred while trying to process your request',
'template' => 'unexpected_error',
],
],
/*
|--------------------------------------------------------------------------
| The data-value to Eloquent method mapping.
|--------------------------------------------------------------------------
|
| In here you can add more keys to the array and Eloquent method name as the value.
| A list of Eloquent methods can be found on this link https://laravel.com/docs/5.3/migrations#creating-columns
| The only time you really have to add more items here is if you don't like using the existing data-value that are used
| with the code generator.
*/
'eloquent_type_to_method' =>
[
'char' => 'char',
'date' => 'date',
'datetime' => 'dateTime',
'datetimetz' => 'dateTimeTz',
'biginteger' => 'bigIncrements',
'bigint' => 'bigIncrements',
'blob' => 'binary',
'binary' => 'binary',
'bool' => 'boolean',
'boolean' => 'boolean',
'decimal' => 'decimal',
'double' => 'double',
'enum' => 'enum',
'list' => 'enum',
'float' => 'float',
'int' => 'integer',
'integer' => 'integer',
'ipaddress' => 'ipAddress',
'json' => 'json',
'jsonb' => 'jsonb',
'longtext' => 'longText',
'macaddress' => 'macAddress',
'mediuminteger' => 'mediumInteger',
'mediumint' => 'mediumInteger',
'mediumtext' => 'mediumText',
'morphs' => 'morphs',
'string' => 'string',
'varchar' => 'string',
'nvarchar' => 'string',
'text' => 'text',
'time' => 'time',
'timetz' => 'timeTz',
'tinyinteger' => 'tinyInteger',
'tinyint' => 'tinyInteger',
'timestamp' => 'timestamp',
'timestamptz' => 'timestampTz',
'unsignedbiginteger' => 'unsignedBigInteger',
'unsignedbigint' => 'unsignedBigInteger',
'unsignedInteger' => 'unsignedInteger',
'unsignedint' => 'unsignedInteger',
'unsignedmediuminteger' => 'unsignedMediumInteger',
'unsignedmediumint' => 'unsignedMediumInteger',
'unsignedsmallinteger' => 'unsignedSmallInteger',
'unsignedsmallint' => 'unsignedSmallInteger',
'unsignedtinyinteger' => 'unsignedTinyInteger',
'uuid' => 'uuid',
],
/*
|--------------------------------------------------------------------------
| Eloquent method to html-type mapping.
|--------------------------------------------------------------------------
|
| This is the mapping used to convert database-column into html field
*/
'eloquent_type_to_html_type' =>
[
'char' => 'text',
'date' => 'text',
'dateTime' => 'text',
'dateTimeTz' => 'text',
'bigIncrements' => 'number',
'bigIncrements' => 'number',
'binary' => 'textarea',
'boolean' => 'checkbox',
'decimal' => 'number',
'double' => 'number',
'enum' => 'select',
'float' => 'number',
'integer' => 'number',
'integer' => 'number',
'ipAddress' => 'text',
'json' => 'checkbox',
'jsonb' => 'checkbox',
'longText' => 'textarea',
'macAddress' => 'text',
'mediumInteger' => 'number',
'mediumText' => 'textarea',
'string' => 'text',
'text' => 'textarea',
'time' => 'text',
'timeTz' => 'text',
'tinyInteger' => 'number',
'tinyInteger' => 'number',
'timestamp' => 'text',
'timestampTz' => 'text',
'unsignedBigInteger' => 'number',
'unsignedBigInteger' => 'number',
'unsignedInteger' => 'number',
'unsignedInteger' => 'number',
'unsignedMediumInteger' => 'number',
'unsignedMediumInteger' => 'number',
'unsignedSmallInteger' => 'number',
'unsignedSmallInteger' => 'number',
'unsignedTinyInteger' => 'number',
'uuid' => 'text',
]
];
I am still unable to reproduce the problems. What Laravel version are you running? What version of Laravel-Code-Generator are you using?
I upgraded 2.0 to 2.1
my composer section about versions...:
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0",
"spatie/laravel-permission": "^1.12"
},
"require-dev": {
"crestapps/laravel-code-generator": "2.1.*",
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.7"
},
Try the following to see if that fixes the problem
composer update
composer dumpautoload
php artisan vendor:publish --provider="CrestApps\CodeGenerator\CodeGeneratorServiceProvider" --tag=default --force
Then execute your commands
php artisan fields-file:create AssetCategory --names=id,name,description,is_active --translation-for=en,ar --force
php artisan create:resources AssetCategory --force
still the same:
but maybe it's just mine problem... I will try clean install and will try
OK, it works on fresh install! The previous installation was purely for testing - there is nothing to worry about...
Glad everything is fine. I am guessing you were using v2.1.0 not v2.1.1. v2.1.2 will be coming up in few hours to fixed a bug in v2.1.1.
I tried to run examples from doc, but got error as below:
php artisan fields-file:create AssetCategory --names=id,name,description,is_active --translation-for=en,ar
it's OK, json was created but then:
php artisan create:resources AssetCategory
and something goes wrong with creating views