barryvdh / laravel-ide-helper

IDE Helper for Laravel
MIT License
14.17k stars 1.16k forks source link

ide-helper always generate id types of int even if string. #1283

Closed letuss004 closed 2 years ago

letuss004 commented 2 years ago

Versions:

Description:

My "users" table has string('id') as primary key but ide-helper always generate id types of int.

Steps To Reproduce:

  1. Change "user" table id from id to string
  2. Use ide-helper:models

image image

mfn commented 2 years ago

ide-helper reads the information directly from the database: are you sure in the environment you're running the helper that the database has the correct column type?

AFAIK there's no special handling for id or primary keys, they're discovered like any other column 🤷‍♀️

lwinmaungmaung commented 2 years ago

Me also the same, +1

khrapeichuk commented 2 years ago

I also managed to reproduce this problem. Generally there is no problem, it's expected behavior for Laravel. The Model abstract class defined primary key type as int:

/**
 * The "type" of the primary key ID.
 *
 * @var string
 */
protected $keyType = 'int';

Source: https://github.com/illuminate/database/blob/master/Eloquent/Model.php#L63

As it's written in Laravel documentation, if you use other type for id you should redefine $keyType property on your model, like this:

protected $keyType = 'string';

Source: https://laravel.com/docs/8.x/eloquent#primary-keys

I think this issue can be closed.

mfn commented 2 years ago

I think this issue can be closed.

Following the suggestion as OP hasn't come back in a month