使用Queueable发送邮件时的Laravel更新模型

时间:2018-12-03 00:09:15

标签: laravel-5.4

我设法使队列系统能够发送带有附件的电子邮件,但是发生这种情况时我无法更新模型。

当然,我在这里遗漏了一些简单的东西,但是不断出现以下错误:

exception 'ErrorException' with message 'Undefined property: App\Jobs\SendStatement::$statement' in /app/Jobs/SendStatement.php:42

我的课:

namespace App\Jobs;

use Mail;
use App\Mail\StatementMail;

use Carbon\Carbon;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class SendStatement implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private $statement;

    public $recipient;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($statement, $recipient)
    {
        $this->statement = $statement;
        $this->recipient = $recipient;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $email = new StatementMail($this->statement, $this->recipient);
        Mail::send($email);
        if( count(Mail::failures()) > 0 ) {

        } else {
            $this->statement->sent = Carbon::now();
            $this->statement->save();
        }
    }
}

0 个答案:

没有答案