Skip to content
This repository was archived by the owner on Jun 11, 2026. It is now read-only.
This repository was archived by the owner on Jun 11, 2026. It is now read-only.

When creating a resource file from the db with a bigint key, the data type is mistakenly set to string and incrementing is set to false in the model. #214

Description

@tcowin

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."
        },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions