I am building a system where manager of employees receives notifications about tasks assigned to his/her employees as well as the employees. Initially, I get the employees from the database like this:
$users = User::whereIn('id', $employeeIds)->with('manager:id,first_name,middle_name,
last_name,email,phone_no')
->get(['id', 'first_name','middle_name', 'last_name', 'email', 'phone_no',
'manager_id']);
Then create a collection of managers for each employee type:
$managers = $users->map(function ($item) {
$manager = $item['manager'];
$parent['employee'] = $item;
return $manager;
});
And finally I send notification to both users via Notification facade.
Notification::send($users, new TaskCompleted($taskData));
Notification::send($managers, new TaskCompleted($taskData));
Now the problem is that let say I have employee A and B both having Manager C as their manager. Notification will send two notifications to Manager C about Employee A only. I have debugged the arrays of data and there is nothing duplicate in there.
Can anyone please help me in the right direction? Should I iterate over the users my self and send individual notifications? As this seems a bug to me in Laravel.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2L1xnOV
via IFTTT
Aucun commentaire:
Enregistrer un commentaire