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

Example of Model with custom attributes #51

Open
dan2k3k4 opened this issue Jun 5, 2024 · 1 comment
Open

Example of Model with custom attributes #51

dan2k3k4 opened this issue Jun 5, 2024 · 1 comment

Comments

@dan2k3k4
Copy link

dan2k3k4 commented Jun 5, 2024

I can't seem to generate typing for custom attributes not part of the database table.

For example:

Database has first_name and last_name fields, but Model has a custom attribute for fullName / full_name e.g.

    protected $attributes = [
        'full_name',
    ];

    protected $appends = [
        'full_name',
    ];
    
    protected function fullName(): Attribute
    {
        return new Attribute(
            get: fn () => $this->first_name . " " . $this->last_name,
        );
    }

However, it does not output full_name on the type .d.ts file after I run ./artisan types:generate

As far as I understand, this package should work with custom attributes.

@Luukdewaaier
Copy link
Member

Hi Dan, at the moment we only support the old attributes (getFullNameAttribute). I will add this to roadmap to also handle this correctly (PRs are also welcome).

One of the problems here is that we cannot determine the type off the attribute if there are no type hints available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants