Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pivot field and columns on a class' relationship aren't recorded in the models helper #1610

Open
abodnar opened this issue Nov 8, 2024 · 0 comments
Labels

Comments

@abodnar
Copy link

abodnar commented Nov 8, 2024

Versions:

  • ide-helper Version: 3.1.0
  • Laravel Version: 10.48.20
  • PHP Version: 8.2.22

Description:

If you have two classes, say User and FeatureFlag and they have a relationship between them and that relationship specifies an extra column that is on the pivot, it is not recorded for the class when generating the models helper.

Example:

class FeatureFlag extends Model
{
    public function users(): BelongsToMany
    {
        return $this->belongsToMany(User::class)
            ->withPivot('enabled')
            ->withTimestamps();
    }
}

Generated helper for model:

namespace App\Models{
/**
 * 
 *
 * @property int $id
 * @property string $name
 * @property string $flag_type
 * @property bool $enabled
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\User> $users
 * @property-read int|null $users_count
 * @method static \Illuminate\Database\Eloquent\Builder|FeatureFlag newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|FeatureFlag newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|FeatureFlag onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|FeatureFlag query()
 * @method static \Illuminate\Database\Eloquent\Builder|FeatureFlag whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|FeatureFlag whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|FeatureFlag whereEnabled($value)
 * @method static \Illuminate\Database\Eloquent\Builder|FeatureFlag whereFlagType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|FeatureFlag whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|FeatureFlag whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|FeatureFlag whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|FeatureFlag withTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|FeatureFlag withoutTrashed()
 * @mixin \Eloquent
 */
	#[\AllowDynamicProperties]
	class IdeHelperFeatureFlag {}
}

This leads to Phpstorm not suggesting and tools like Larastan complaining about not finding the fields.

Related issue in Larastan, larastan/larastan#1774

@abodnar abodnar added the bug label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant