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

Fix return types of firstWhere and first of BelongsToMany and HasManyThrough #51219

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

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?

* @return \Illuminate\Database\Eloquent\Model|static|null
Copy link
Contributor Author

@SanderMuller SanderMuller Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return \Illuminate\Database\Eloquent\Model|static|null
* @return \Illuminate\Database\Eloquent\Model|null

Unless I'm mistaken, this should be correct

*/
public function firstWhere($column, $operator = null, $value = null, $boolean = 'and')
{
Expand All @@ -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
Copy link
Contributor Author

@SanderMuller SanderMuller Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return \Illuminate\Database\Eloquent\Model|static|null
* @return \Illuminate\Database\Eloquent\Model|null

*/
public function first($columns = ['*'])
{
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

@SanderMuller SanderMuller Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return \Illuminate\Database\Eloquent\Model|static|null
* @return \Illuminate\Database\Eloquent\Model|null

*/
public function firstWhere($column, $operator = null, $value = null, $boolean = 'and')
{
Expand All @@ -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
Copy link
Contributor Author

@SanderMuller SanderMuller Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return \Illuminate\Database\Eloquent\Model|static|null
* @return \Illuminate\Database\Eloquent\Model|null

Copy link
Member

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.

Copy link
Contributor Author

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!

Copy link
Contributor Author

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

Copy link
Member

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

*/
public function first($columns = ['*'])
{
Expand Down