【发布时间】:2020-02-27 09:57:50
【问题描述】:
在我的 Web 应用程序项目中使用 Laravel-5.8,我有这个 Notification 类:
namespace App\Notifications;
use http\Url;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class AppraisalGoalPublish extends Notification implements ShouldQueue
{
use Queueable;
public function __construct()
{
}
public function via($notifiable)
{
return ['mail','database'];
}
public function toMail($notifiable)
{
return (new MailMessage)
}
public function toDatabase()
{
return [
];
}
public function toArray($notifiable)
{
return [
//
];
}
}
还有这个控制器
public function publish_all_posts(){
$userCompany = Auth::user()->company_id;
$userEmployee = Auth::user()->employee_id;
$userId = Auth::user()->id;
$userEmail = Auth::user()->id;
$userCode = Auth::user()->employee_code;
$userFirstName = Auth::user()->first_name;
$userLastName = Auth::user()->last_name;
$identities = DB::table('appraisal_identity')->select('id')->where('company_id', $userCompany)->where('is_current', 1)->first();
$reviewperiod = DB::table('appraisal_identity')->select('appraisal_name')->where('company_id', $userCompany)->where('is_current', 1)->first();
$linemanager = DB::table('hr_employees')->select('line_manager_id')->where('id', $userEmployee)->first();
$linemanageremail = DB::table('hr_employees')->select('email')->where('line_manager_id', $linemanager)->pluck('email');
$linemanagerid = DB::table('hr_employees')->select('id')->where('line_manager_id', $linemanager)->pluck('id');
$unapproved_count = AppraisalGoal::where('employee_id', $userEmployee)->where('appraisal_identity_id', $identities->id)->where('is_published',0)->count();
if ($unapproved_count > 3){
$unapproved_post = AppraisalGoal::where('employee_id', $userEmployee)->where('appraisal_identity_id', $identities->id)->where('is_published',0)
->update([
'is_published' => 1,
'is_approved' => 1
]);
Session::flash('success', 'Goals Published successfully');
return redirect()->back();
}else{
Session::flash('info', 'You cannot proceed. Kindly Set all Goals before you publish!');
return redirect()->back();
}
}
我想发送邮件通知并在publish_all_posts()提交时保存到数据库中
我想向
$linemanageremail发送邮件通知: 代码为 $userCode 且名称为$FirstName. ' ' . $LastName的员工已发布了他/她在审核期间的目标$reviewperiod以供您批准。谢谢将邮件通知的内容保存到通知表中: 以
$userId为发送者,$linemanagerid为接收者,邮件内容为数据。
我如何完成我的 AppraisalGoalPublish 和控制器以实现这些目标?
谢谢。
【问题讨论】:
标签: laravel