While doing a script which is used to send users a notification one day before their subscription ends, will fetch the users by joining users and subscription table. I was using chunkById only with three parameters (without the alias param) which resulted in an infinite loop of users fetching.
Because of this users are getting infinite push notifications. I was getting a call that users were getting lots of notifications.
Can someone please explain how chunkById work upon ambiguous column?
Query which I have used:
$result = User::join ('subscription', 'subscription.user_id', '=', 'user.id')
->where('subscription.status, '1')
->chunkById(50, function ($datas){
foreach( $datas as $data ) {
sendNotification();
}
}, 'user.id');
// I have skipped some where conditions
laravel : 5.8
php : 7.3
database : mysql
The above query results me the same first 50 users again and again, then after reading a Stackoverflow answer I tried the third parameter as ‘user.id’ and the fourth parameter as ‘id’ then it gave me the correct result. I don’t know why this is happening. Can anyone please explain how chunkById works? I also checked the official doc and I didn’t get the answer.
Abi nash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.