发送每周报告的命令

时间:2019-04-28 07:34:20

标签: php laravel dompdf

我正在尝试创建一个命令,该命令将自动发送带有每周报告的电子邮件,该报告是使用dompdf库以pdf格式生成的,在尝试执行该命令时出现以下错误。

  

未定义的属性:App \ Console \ Commands \ SendWeeklyReport :: $ pdf

SendWeeklyReport.php

public function handle()
{
    //
    $date = \Carbon\Carbon::today()->subDays(7);
    $assignees = assignee::select("*")
                         ->where('created_at', '>=', $date)
                         ->get();
      $pdf = PDF::loadView('assignees.pdf', compact('assignees'))->setPaper('a4', 'landscape');
      $name = 'Report Generated at '.Carbon::today()->toDateString() .'.pdf';
      $data = array(
    'email_address'=>'email',
    'cc'=>'email',
    'subject'=>"weekly report"
);
    Mail::send('assignee.email', $data, function($message) use($data) {
 $message->from('admin@localhost.com');
 $message->to($data['email_address']);
 if($data['cc'] != null){
     $message->cc($data['cc']);
 }
 $message->subject($data['subject']);
 $message->attachData($this->pdf, $name, [
                'mime' => 'application/pdf',
            ]);
          });
          $this->info('Email sent successfully!');
}

我已经将命令添加到Kernel.php

protected $commands = [
    //
    Commands\SendWeeklyReport::class,
];

0 个答案:

没有答案