-
Notifications
You must be signed in to change notification settings - Fork 11.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
Fix return types of firstWhere
and first
of BelongsToMany
and HasManyThrough
#51219
Conversation
firstWhere
and first
of BelongsToMany
and HasManyThrough @SanderMuller
firstWhere
and first
of BelongsToMany
and HasManyThrough
We might want to target this to 10.x instead |
@@ -784,7 +784,7 @@ public function findOr($id, $columns = ['*'], ?Closure $callback = null) | |||
* @param mixed $operator | |||
* @param mixed $value | |||
* @param string $boolean | |||
* @return \Illuminate\Database\Eloquent\Model|static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am also not sure why this returns |static
, in which case does it return an instance of BelongsToMany
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop static
as return types
@@ -784,7 +784,7 @@ public function findOr($id, $columns = ['*'], ?Closure $callback = null) | |||
* @param mixed $operator | |||
* @param mixed $value | |||
* @param string $boolean | |||
* @return \Illuminate\Database\Eloquent\Model|static | |||
* @return \Illuminate\Database\Eloquent\Model|static|null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return \Illuminate\Database\Eloquent\Model|static|null | |
* @return \Illuminate\Database\Eloquent\Model|null |
Unless I'm mistaken, this should be correct
@@ -795,7 +795,7 @@ public function firstWhere($column, $operator = null, $value = null, $boolean = | |||
* Execute the query and get the first result. | |||
* | |||
* @param array $columns | |||
* @return mixed | |||
* @return \Illuminate\Database\Eloquent\Model|static|null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return \Illuminate\Database\Eloquent\Model|static|null | |
* @return \Illuminate\Database\Eloquent\Model|null |
@@ -320,7 +320,7 @@ public function updateOrCreate(array $attributes, array $values = []) | |||
* @param mixed $operator | |||
* @param mixed $value | |||
* @param string $boolean | |||
* @return \Illuminate\Database\Eloquent\Model|static | |||
* @return \Illuminate\Database\Eloquent\Model|static|null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return \Illuminate\Database\Eloquent\Model|static|null | |
* @return \Illuminate\Database\Eloquent\Model|null |
@@ -331,7 +331,7 @@ public function firstWhere($column, $operator = null, $value = null, $boolean = | |||
* Execute the query and get the first related model. | |||
* | |||
* @param array $columns | |||
* @return mixed | |||
* @return \Illuminate\Database\Eloquent\Model|static|null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return \Illuminate\Database\Eloquent\Model|static|null | |
* @return \Illuminate\Database\Eloquent\Model|null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use the ?
in docblocks itself. null
is what we use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use the
?
in docblocks itself.null
is what we use.
Updated!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@driesvints can you confirm in static
can be dropped? Then I can create a follow-up PR for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just leave things be for now. Thanks
The current return types of
firstWhere
does not includenull
, while it ends up calling->first()
which can returnnull
(when there's no results).This change improves the IDE intellisense and fixes false positives static analyser errors, for example this Larastan error: