Property $id accessed via magic method.
Hi
I'm not really sure why I get this error for all all the $model->id:
Property $id accessed via magic method.
Laravel Code
protected static function boot(): void
{
parent::boot();
static::creating(function (self $model): void {
$model->setDefaultSettings();
});
static::created(function (self $model): void {
$model->makeUserDirectories();
});
static::deleted(function (self $model): void {
$model->deleteUserDirectories();
UserNotification::whereUserId($model->id)->delete();
UserWebhook::whereUserId($model->id)->delete();
UserSignature::whereUserId($model->id);
UserDocTemplate::whereUserId($model->id)->whereNull('team_id')->delete();
UserDoc::whereUserId($model->id)->whereNull('team_id')->delete();
UserEmailTemplate::whereUserId($model->id)->whereNull('team_id')->delete();
});
}
This low-severity message warns about a dynamic property that is not defined while other dynamic properties are defined with @property tag. (https://docs.devsense.com/vs/code%20validation/diagnostics/#hint:~:text=or%20simpler%20form.-,PHP6602,-MagicMethodField)
Recommended actions are:
- add
@property int $idon your model (where the other@propertytags are) - or suppress the warning
Once the other model attributes are defined with @property tag, the editor expects that user knows what he does :)
Not absolutely correct.
The issue here is that it is not all properties but only some that trigger this warning / error.
I saw that i for some reason had this:
/**
* @property string $current_team_id
* @property datetime $email_verified_at
*/
on the model, when that is removed, then the 'warning' goes away
Yes, that is what the error says: "Some properties are defined using @property", so if you use ->id which is not defined using @property, but other properties are, it is possibly an error.
In short - either define all dynamic properties using @property or none of them.
If you defined "just some", the editor assumes you forgot.