Skip to content

[Feature Request]: Autocomplete custom cast of collection of objects #1327

Description

@dsazup

Feature Description

This feature request is made of two parts. The first part might actually be a bug.

When we use a cast in the model like so:

class Person extends Model
{
   protected function casts(): array
    {
        return [
            'emails' => AsCollection::of(ContactEmail::class),
        ];
    }
}

The genereated helper code is:

  /**
     * @property ContactEmail[]|Collection<array-key, App\Values\ContactEmail>|null $emails

Notice that the namespace for App\Values\ContactEmail is missing a prefix slash. So if I do:

$person->emails

I get this autocomplete:
Image

but if I do $emails = $person->emails()->first->
I get no autocomplete. If I manually change generated helper code and add a prefix \ it works

Image

Would it be possible to fix this? Also if I do emails' => AsCollection::of('\App\Values\ContactEmail'), (a class name as a string) it works correctly.


Additionally, if we use any other custom cast besides laravel's AsCollection or spatie's equivalent, there's no autocomplete whatsover. For example using this package

https://bagvalueobjects.com/laravel-eloquent-casting.html#casting-collections

if I have

class Person extends Model
{
   protected function casts(): array
    {
        return [
            'emails' => AsCollection::of(ContactEmail::class),
        ];
    }
}

I get no autocomplete and generated helper code is just

* @property array|null $emails

Is there any way to make this autocomplete work?

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions