-
-
Notifications
You must be signed in to change notification settings - Fork 424
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
Description of relationships #2071
Comments
This should be: /**
* @return BelongsTo<User, $this>
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
} |
Or just avoid the |
The |
Same error:
|
Make sure to clear any cache, |
Thanks for this tip, but unfortunately, it didn't solve. Same errors as @koraga |
There is no error if I add |
What does the full Model look like? By any chance are they |
Yes, all my models are |
Ah, that's it---I can replicate it now. This looks like a PHPStan bug, I'll open an issue over there |
My Models are not |
@davideprevosto, then there's also a bug in Larastan because non- |
Same issue here. Cache cleared etc. On my end it is not related to final/non-final. Caleb, I tried your fork and have the same result. Worth to mention that this is old code that used to work without reports. /** @return BelongsTo<\App\Models\Company, \App\Models\MultisiteInquiry> */
public function company(): BelongsTo
{
return $this->belongsTo(Company::class, 'company_id');
}
Seems to me like it is a regression in Larastan 2.9.9.
|
This error is correct, your generic should be: /** @return BelongsTo<\App\Models\Company, $this> */ |
Thanks @calebdw. Not trying to argue, but please allow me to double confirm:
|
Yes it is intentional, and Using |
Thank you for taking the time to explain! I get the intention. Would have been nice if there would have been a fade-out phase until the next major were both the most correct The above just as an aside. I appreciate all your hard work here, and in other repos. Thanks.🤝 |
There was talk about releasing this in v3, but we're going to release v3 when PHPStan is bumped to v2 so it was just decided to go ahead and release this to support Laravel >11.15
This isn't as easy to do as it sounds. The dynamic return type extension has to return one value so it's kind of one or the other without a ton of complicated checks
Thank you! You are too kind---I'm always happy to help 😄 |
Line app/Models/Support/FooTrait.php (in context of class App\Models\Bar)
------ -------------------------------------------------------------------------------------------------------------------------------------------------------
90 Method App\Models\Bar::getDate() should return Illuminate\Database\Eloquent\Collection<int, App\Models\Bar> but
returns Illuminate\Database\Eloquent\Collection<int, static(App\Models\Bar)>. The static method getDate() is declared in the FooTrait located in app/Models/Support/FooTrait. It returns a static::query(), and using this FooTrait in a final class will trigger the aforementioned error. |
There's an open issue at PHPStan. In the meantime you can either: 1) ignore the error, or 2) remove |
Description
Hi. How to describe relationships correctly?
To my description
an error occurs
Laravel code where the issue was found
The text was updated successfully, but these errors were encountered: