Closed
Description
Laravel Version
12.x
PHP Version
8.3.15
Database Driver & Version
SQLite on macOS 15.3 (Laravel Herd on ARM64)
Description
After PR #54443 was merged into the 12.x
branch, I'm facing a bug when using pluck()
on the Query Builder. I updated my demo app to the commit before the merge and to the commit of the merge, and it still worked before the merge. The problem was even briefly mentioned in the PR itself.
Here's a simplified version of my code that breaks:
Building::query()->selectSub(
DB::table('building_user')
->select('building_user.user_id')
->whereColumn('building_user.building_id', 'buildings.id')
->limit(1),
'user_id'
)->pluck('user_id');
Before the PR, this would result in the following query:
select
(
select
"building_user"."user_id"
from
"building_user"
where
"building_user"."building_id" = "buildings"."id"
limit
1
) as "user_id"
from
"buildings"
The pluck()
method would simply give me a Collection
with the fetched user IDs:
Illuminate\Support\Collection {#2746
all: [
1,
1,
2,
2,
...
],
}
After the PR, it only executed SELECT "user_id" FROM "buildings"
, resulting in many of these warnings:
WARNING Undefined property: stdClass::$user_id in vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php on line 3432.
Steps To Reproduce
I checked the example above by updating laravel/framework
to specific commits:
Before:
"laravel/framework": "12.x-dev#f03d3a17412bf3c71cb291dc09ec0acc308afac7"
After:
"laravel/framework": "12.x-dev#ca7ca2cddeff32427ca67c8bfd1e0f8a778a074c"