Skip to content

Commit beb21f5

Browse files
committed
fix: bonEarnings() method with explicit column selection to avoid ambiguity
1 parent 19f465c commit beb21f5

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

app/Http/Livewire/UserEarnings.php

+29-11
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,25 @@ final public function bonEarnings(): \Illuminate\Support\Collection
7171
{
7272
$outerQuery = DB::query();
7373
$innerQuery = Peer::query()
74-
->join('history', fn ($join) => $join->on('history.torrent_id', '=', 'peers.torrent_id')->on('history.user_id', '=', 'peers.user_id'))
74+
->select([
75+
'peers.torrent_id',
76+
'peers.user_id',
77+
'torrents.name',
78+
'torrents.created_at as torrent_created_at',
79+
'torrents.size',
80+
'torrents.seeders',
81+
'torrents.leechers',
82+
'torrents.times_completed',
83+
'torrents.internal',
84+
'torrents.personal_release',
85+
'torrents.type_id',
86+
'history.seedtime',
87+
'peers.connectable'
88+
])
89+
->join('history', function ($join): void {
90+
$join->on('history.torrent_id', '=', 'peers.torrent_id')
91+
->on('history.user_id', '=', 'peers.user_id');
92+
})
7593
->join('torrents', 'peers.torrent_id', '=', 'torrents.id')
7694
->where('peers.seeder', '=', true)
7795
->where('peers.active', '=', true)
@@ -87,16 +105,16 @@ final public function bonEarnings(): \Illuminate\Support\Collection
87105
foreach ($bonEarning->conditions as $condition) {
88106
$conditionQuery .= ' AND '.match ($condition->operand1) {
89107
'1' => '1',
90-
'age' => 'TIMESTAMPDIFF(SECOND, torrents.created_at, NOW())',
91-
'size' => 'torrents.size',
92-
'seeders' => 'torrents.seeders',
93-
'leechers' => 'torrents.leechers',
94-
'times_completed' => 'torrents.times_completed',
95-
'internal' => 'torrents.internal',
96-
'personal_release' => 'torrents.personal_release',
97-
'type_id' => 'torrents.type_id',
98-
'seedtime' => 'history.seedtime',
99-
'connectable' => 'peers.connectable',
108+
'age' => 'TIMESTAMPDIFF(SECOND, torrent_created_at, NOW())',
109+
'size' => 'size',
110+
'seeders' => 'seeders',
111+
'leechers' => 'leechers',
112+
'times_completed' => 'times_completed',
113+
'internal' => 'internal',
114+
'personal_release' => 'personal_release',
115+
'type_id' => 'type_id',
116+
'seedtime' => 'seedtime',
117+
'connectable' => 'connectable',
100118
}.' '.$condition->operator.' '.$condition->operand2;
101119
}
102120

0 commit comments

Comments
 (0)