如何根据 Laravel 中的条件发送批量通知
How to send bulk notifications based on conditions in Laravel
我在 Laravel-5.8 上有一个项目。我正在尝试根据条件向电子邮件发送批量通知:
public function employee_notifications()
{
$userCompany = Auth::user()->company_id;
$userEmployee = Auth::user()->employee_id;
$employeeCode = Auth::user()->employee_code;
$userId = Auth::user()->id;
$employeeemail = DB::table('hr_gradings')->select('email')->where('respondent_id', $userId)->get();
$condition1 = DB::table('hr_gradings')->where('employee_type', 0)->get();
$condition2 = DB::table('hr_gradings')->where('employee_type', 1)->get();
DB::beginTransaction();
try {
$details = [
'sent_to' => '',
'sent_by' => $userI'',
'subject' => 'Mid-Year Self-Review Approved by : ' .$userFirstName .' for '.$reviewperiod,
'greeting' => 'Dear '.$employeefirstname . ' '. $employeelastname . ',',
'body' => 'Some text. ' . 'Proceed to see review comments .',
'line1' => 'some text 2',
'line2' => 'Proceed to see review comments .',
'thanks' => 'Thank you!',
'actionText' => 'My Self-Review',
'actionURL' => url('http://localhost:8888/employees/testing1'),
'employee_email' => '',
];
Notification::route('mail', $details['employee_email'])
->notify(new \App\Notifications\Testing($details));
DB::commit();
Session::flash('success', 'successfully');
return redirect()->back();
} catch (Exception $exception) {
DB::rollback();
Session::flash('error', 'Action failed! Please try again');
return redirect()->back();
}
}
到目前为止,我拥有的是单个用户电子邮件。
如果
$condition = DB::table('hr_gradings')->where('employee_type', 0)->get();
它应该向所有人发送通知
$employeeemail = DB::table('hr_gradings')->select('email')->where('respondent_id', $userId)->get();
其中 employee_type = 0
并使用此操作 url:'actionURL' => url('http://localhost:8888/employees/testing1'),
但是如果
$condition = DB::table('hr_gradings')->where('employee_type', 1)->get();
它应该向所有人发送通知
$employeeemail = DB::table('hr_gradings')->select('email')->where('respondent_id', $userId)->get();
其中 employee_type = 1
并使用此操作 url:'actionURL' => url('http://localhost:8888/employees/testing2'),
我怎样才能做到这一点并得到这个employee_email?
//Loop the code using for each
foreach $condition2 as $bulkemail
{
//insert here the sending email code
//replace 'sent_to' => '',
'sent_to' => '$bulkemail->email',
}
我在 Laravel-5.8 上有一个项目。我正在尝试根据条件向电子邮件发送批量通知:
public function employee_notifications()
{
$userCompany = Auth::user()->company_id;
$userEmployee = Auth::user()->employee_id;
$employeeCode = Auth::user()->employee_code;
$userId = Auth::user()->id;
$employeeemail = DB::table('hr_gradings')->select('email')->where('respondent_id', $userId)->get();
$condition1 = DB::table('hr_gradings')->where('employee_type', 0)->get();
$condition2 = DB::table('hr_gradings')->where('employee_type', 1)->get();
DB::beginTransaction();
try {
$details = [
'sent_to' => '',
'sent_by' => $userI'',
'subject' => 'Mid-Year Self-Review Approved by : ' .$userFirstName .' for '.$reviewperiod,
'greeting' => 'Dear '.$employeefirstname . ' '. $employeelastname . ',',
'body' => 'Some text. ' . 'Proceed to see review comments .',
'line1' => 'some text 2',
'line2' => 'Proceed to see review comments .',
'thanks' => 'Thank you!',
'actionText' => 'My Self-Review',
'actionURL' => url('http://localhost:8888/employees/testing1'),
'employee_email' => '',
];
Notification::route('mail', $details['employee_email'])
->notify(new \App\Notifications\Testing($details));
DB::commit();
Session::flash('success', 'successfully');
return redirect()->back();
} catch (Exception $exception) {
DB::rollback();
Session::flash('error', 'Action failed! Please try again');
return redirect()->back();
}
}
到目前为止,我拥有的是单个用户电子邮件。
如果
$condition = DB::table('hr_gradings')->where('employee_type', 0)->get();
它应该向所有人发送通知
$employeeemail = DB::table('hr_gradings')->select('email')->where('respondent_id', $userId)->get();
其中 employee_type = 0
并使用此操作 url:'actionURL' => url('http://localhost:8888/employees/testing1'),
但是如果
$condition = DB::table('hr_gradings')->where('employee_type', 1)->get();
它应该向所有人发送通知
$employeeemail = DB::table('hr_gradings')->select('email')->where('respondent_id', $userId)->get();
其中 employee_type = 1
并使用此操作 url:'actionURL' => url('http://localhost:8888/employees/testing2'),
我怎样才能做到这一点并得到这个employee_email?
//Loop the code using for each
foreach $condition2 as $bulkemail
{
//insert here the sending email code
//replace 'sent_to' => '',
'sent_to' => '$bulkemail->email',
}