Uh oh!
There was an error while loading. Please reload this page.
[5.x] Add pluck to query builder - #9686
Conversation
This implementation will resolve values from the Stache indexes
I think this is fine. We could justify it as the same thing happening with Eloquent models and accessors. Calling class Post extends Model
{
protectedfunctionformattedTitle(): Attribute
{
return Attribute::make(
get: fn ($value, $attributes) => Str::title($attributes['title']),
);
}
}
Post::query()->pluck('title'); // ['post one', 'post two']
Post::query()->pluck('formattedTitle'); // QueryException Unknown column formattedTitle
Post::query()->get()->pluck('formattedTitle'); // ['Post One', 'Post Two'] |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jasonvarga
left a comment
There was a problem hiding this comment.
There's a bunch of code in this PR that when removed still passes.
If it's necessary, can you please add test coverage?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- make getItemValues abstract like getItem is. - move implementation into BasicStore like getItem - aggregatestore version delegates to individual stores like getitem - prevent the query builder from doing Str::after the divider, now that the aggregatestore handles that - add test to entry query builder test with multiple collections to show it works - use id- prefix for ids in test to make it more obvious what are keys vs just array indexes. its confusing when debugging.
- make private as its only used in one place now. - adjust comment - use 'filter' since 'where' calls filter anyway
This PR implements
pluckmethod on the query builder.Note: this implementation currently only resolves values from the Stache indexes, but a fallback to gathering data from entry instances could also be added if desired 🙂