laravel-idea / plugin

Laravel Idea plugin for PhpStorm
https://laravel-idea.com/
177 stars 7 forks source link

[Bug]: Columns added via macros in migrations not recognised as attributes #1067

Open cornelRaiu opened 2 months ago

cornelRaiu commented 2 months ago

Bug description

I am using the Spatie / Schemaless Attributes package which has a schema macro for adding a schemaless attributes column:

Blueprint::macro('schemalessAttributes', function (string $columnName = 'schemaless_attributes') {
    return $this->json($columnName)->nullable();
});

After adding it to my migration like this:

Schema::table('offers', function (Blueprint $table) {
    $table->schemalessAttributes('extra_attributes');
});

And setting up my model as described in the package:

protected function casts(): array
{
    return [
        'extra_attributes' => SchemalessAttributes::class
    ];
}

public function scopeWithExtraAttributes(): Builder
{
    return $this->extra_attributes->modelScope();
}

I run the helper code generation but the extra_attributes attribute is not added to the model attributes list:

image

However, if I add the column in my migration without using the macro, everything works as expected without changing anything else:

Schema::table('offers', function (Blueprint $table) {
    $table->json('extra_attributes')->nullable();
});

image

Plugin version

8.2.5.242

Operating system

MacOS

Steps to reproduce

  1. Register a macro in a service provider
Blueprint::macro('testMacro', function (string $columnName) {
    return $this->string($columnName)->nullable();
});
  1. Add 2 columns to a model, one using the macro and one directly adding the type in the migration:
Schema::table('test_models', function (Blueprint $table) {
    $table->testMacro('test_column');
    $table->string('test_column2');
});
  1. Run the helper code generator
  2. Try to use the test_column somewhere in the code:
public function testing() 
{
    $testModel->test_column;
}
  1. Try to navigate to the property by using the middle mouse button or cmd/ctrl + left click. It will not work and, in some cases, you might even see it highlighted for being accessed via magic methods:
  2. image

However, the test_column2 is working as expected:

image

Relevant log output

No response