Description
This is a wonderful package and I've used it with several projects over the years (Many Thanks!), but have been modifying created models to correct this issue for a while, and I wanted to try to resolve this issue...
Environment:
- Laravel-Code-Generator Version: 3.0.2
- Laravel Version: 11.36.1
Description:
If my PK is a bigint, the data type gets set to string as the ParserBase::getHtmlType also uses the eloquent_type_to_html_type map, but there's not a key 'bigInteger' with a capital I, so it defaults to string. What we end up with in the model is this:
/**
* The database primary key value.
*
* @var string
*/
protected $primaryKey = 'id';
protected $keyType = 'string';
public $incrementing = false;
When, ideally, no code would get added to the model as the default for PrimaryKey is id.
If I add a line to the map that accounts for this key like so 'bigInteger' => 'bigInteger', it works correctly, but I don't know if that is ideal as a fix. It seems there could be other issues with case sensitivity as you have other values in this map that are mixed case. Not sure if a strtolower on the key before the lookup in getHtmlType is optimal in all cases...?
Steps/Commands To Reproduce:
Run php artisan resource-file:from-database modelname on a database table with a bigint primary key.
Content Of The Resource-File:
{
"fields": [
{
"name": "id",
"labels": "Id",
"html-type": "text",
"css-class": "",
"options": {},
"html-value": null,
"validation": "",
"is-on-index": false,
"is-on-show": false,
"is-on-form": false,
"data-type": "string",
"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": "Enter id here...",
"delimiter": "; ",
"range": [],
"foreign-relation": null,
"foreign-constraint": null,
"on-store": null,
"on-update": null,
"api-key": "id",
"is-api-visible": true,
"api-description": "The id of the model."
},