-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fixbug in pluck function #3168
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
fixbug in pluck function #3168
Conversation
Fix bug in pluck function. Cannot use object of type stdClass as array
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.
Thank you @fuyuki0511 for contributing. I really appreciate.
Also, could you add a test in QueryBuilderTest. Something like this:
public function testPluckObjectId() { DB::table('users')->insert([ ['id' => $id = new ObjectId(), 'name' => 'Jane Doe', 'age' => 20], ]); $names = DB::table('users')->pluck('name', 'id')->toArray(); $this->assertCount(1, $names); $this->assertArrayHasKey((string) $id, $names); $this->assertEquals([(string) $id => 'Jane Doe'], $names); }
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 think this piece of code can be removed as Arr::pluck already convert stringable key value into string. https://github.com/laravel/framework/blob/646520ad682d98b5211c6e26092259cfbe130b5c/src/Illuminate/Collections/Arr.php#L562
I see you created a new PR #3169. You could have pushed to the same branch to update this PR and keep the discussion in the same place.
Fix bug in pluck function.
Cannot use object of type stdClass as array
Checklist