plugin icon indicating copy to clipboard operation
plugin copied to clipboard

[Bug]: Attribute accessors should override properties defined in Sushi `$schema` property

Open aguingand opened this issue 2 years ago • 0 comments

Bug description

Following up on https://github.com/laravel-idea/plugin/issues/737. When I'm using attribute accessor in parallel with Sushi's $schema, the helper code keeps the type defined in $schema instead of using the one returned by the accessor.

It's ok with $casts though.

Plugin version

7.2.0.231

Operating system

MacOS

Steps to reproduce

  • In a laravel project, install calebporzio/sushi package.
  • Create a model using Sushi
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Sushi\Sushi;

class Page extends Model
{
    use Sushi;

    protected array $schema = [
        'visuals' => 'string',
    ];

    public function getRows()
    {
        return []
    }

    public function visuals(): Attribute
    {
        return Attribute::make(fn ($visuals) => collect());
    }
}
  • Click "Generate Helper code"
  • Go to the vendor/_laravel_idea/ide_helper_models*.php file containing the model definition
  • Property $visuals is defined as string instead of Collection. (If you comment the schema, it works)

Relevant log output

No response

aguingand avatar Jul 25 '23 09:07 aguingand