laravel-ide-helper: Duplicate property creation every time it runs
Versions:
- ide-helper Version: v2.13.0
- Laravel Version: v9.52.0
- PHP Version: 8.2
Description:
After updating to the latest version, every time I run the php artisan ide-helper:models --write command, the property-read in the model is added again, causing duplicate values in the model.
/**
* App\Models\Branch
*
* @property int $id
* @property int $company_id
* @property string $name
* @property string|null $phone
* @property bool $active
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\QrMenu> $activeQrMenus
* @property-read int|null $active_qr_menus_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, User> $admins
* @property-read int|null $admins_count
* @property-read \App\Models\Company $company
* @method static \Database\Factories\Company\BranchFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|Branch newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Branch newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Branch query()
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\QrMenu> $activeQrMenus
* @property-read \Illuminate\Database\Eloquent\Collection<int, User> $admins
* @mixin \Eloquent
*/
The activeQrMenus and admins values here are repeating.
There are many models in the project, but this error only occurs in 5 models.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 12
- Comments: 22 (1 by maintainers)
@barryvdh can you help please?)
https://github.com/barryvdh/ReflectionDocBlock/compare/v2.1.0...v2.1.1 fixed here if running
composer updatecommandI can’t use
--resetbecause I’ve defined some model getters using Laravel’s Attribute, and when I add--reset, it deletes the manually added properties.FYI I needed to fix this because it caused my CI to fail every time. How I fixed is by changing the command to
php artisan ide-helper:models --no-interaction --write --reset. The--resetflag resets the lookup and re-populates the models.+1 can we get that dependency updated?
Same problem here. Just a bit of knowledge since it’s not mentioned in this thread. In my case, it only happens if there was something “irregular” with the naming convention.
For example the model is User but the relation is called admins. Or if it’s two words like payment_logs. Or if it’s 1 word, but you’re not using standard column naming like user_id for a foreign key on users
+1 on this issue
Same issue. However, I found out, that
use_generics_annotationsset totruewill produce duplicates like thisI ran it three times with this setting and it always seem to duplicate the
@property-readfromHasApiTokensandNotifiablein my default User model. Switching the generics annotations off fixes this issue (requires deleting the previous model docBlock)Related block:
https://github.com/barryvdh/laravel-ide-helper/blob/4dc20b028adaeadf603860f179f09da5aa21f5b5/src/Console/ModelsCommand.php#L748
Both mentioned traits indeed extend from
Relation, so maybe it just can’t match the correct type for collections of those relations.yes, it is always on
CollectionIs it always on
Collections?