-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Laravel built in casts now have incorrect type documented #1423
Comments
I am now seeing that #1393 exists but it is also missing types for the 5 other casts that Laravel has. If that turns out to be the proper way to solve this I can make a pull containing all of them. |
I'm running into this same issue, wish there was a workaround to just update the config until this is either fixed upstream in laravel or here in this package. |
@jamesrusso My workaround is to keep generated model types in separate file and manually over-ride broken types only in the relevant model files. |
I was able to fix this by adding the following to the /*
|--------------------------------------------------------------------------
| Property Casts
|--------------------------------------------------------------------------
|
| Cast the given "real type" to the given "type".
|
*/
'type_overrides' => [
'integer' => 'int',
'boolean' => 'bool',
'\\'.AsCollection::class => '\Illuminate\Support\Collection',
'\\'.AsArrayObject::class => '\ArrayObject',
], |
Fixed with #1393? |
Versions:
Description:
Using Laravel built in casts such as
Illuminate\Database\Eloquent\Casts\AsCollection
will now return it as its own class, which doesn't actually implement a Collection meaning it will error out even when using it properly. Previously it returned as mixed which at least didn't error. The change causing this is #1388 but is more down to the actual Laravel class not having type hints for the get method. This could be fixed on the Laravel side, or it could be extracted from the docblock return from thecastUsing
function. I did test with making a modification here but I got stuck as I believe theCastsAttributes
wrapper in the docblock would need to be stripped for proper functionality and I wasn't quite sure on the best way to do thatSteps To Reproduce:
php artisan ide-helper:model -M
@property \Illuminate\Database\Eloquent\Casts\AsCollection $collection
The text was updated successfully, but these errors were encountered: