barryvdh/laravel-ide-helper

Models that have `static::$snakeAttributes` set to `true` should use attribute names without case conversion

func0der opened this issue · 0 comments

Versions:

  • ide-helper Version: master
  • Laravel Version: 10.17.1
  • PHP Version: 8.1

Description:

If I understand the code in \Illuminate\Database\Eloquent\Concerns\HasAttributes that relies on the \Illuminate\Database\Eloquent\Concerns\HasAttributes::$snakeAttributes property correctly, the column namens coming from the database are used untouched as attributes in the models have set $snakeAttributes = false.

So column fooBar will be attribute fooBar and column foo_bar will become attribute foo_bar.

In the config we have the variable model_camel_case_properties which can be used to configure the behavior of the ide helper during generation of model php docs.
It is as document an "all or nothing" approach.

Instead of that, could we just see in the models, which as far as I understand are reflected and inspected anyway, check for that $snakeAttributes property being set to false and let the ide helper generate the PHPDoc accordingly?

Steps To Reproduce:

  • Have a model with $snakeAttributes = false
  • Have a database column on that model in camelCase
  • Have a database column on that model in snake_case
  • Generate model docs

Should be something along the lines:

 * @property string $camelCase
 * @property string $snake_case

What do you think?

I am fairly new to Laravel, Eloquent and the sorts, so I appreciate any new insights you can give me into this :)

P.S.: Thanks for your awesome work ;)