model = Email::lockForUpdate()->findOrfail($param); $this->canSend = $this->model->send_datetime === null; if (!$this->checkAuth()) throw new AppCommonException("メール権限エラー"); } else if ($param instanceof BaseMailer) { $this->model = $param->makeModel(); } } public function checkAuth() { return true; } public function getEmailId() { return $this->model->id; } public function getTimestamp(): Carbon|null { return $this->model->updated_at; } public function create() { $this->model->save(); return []; } public function setSubject(string $subject) { if ($this->canSend()) { $this->model->subject = $subject; } else { throw new AppCommonException("送信済みメール編集エラー"); } return $this; } public function setContent(string $content) { if ($this->canSend()) { $this->model->content = $content; } else { throw new AppCommonException("送信済みメール編集エラー"); } return $this; } public function update() { $this->model->save(); return []; } public function confirm() { $validator = Validator::make(['email' => $this->model->email], [ 'email' => ['required', 'email:strict,dns'] ]); if ($validator->fails()) { throw new Exception(sprintf("%s [%s]", $validator->errors()->first(), $this->model->email)); } if ($this->canSend() !== null) { ConfirmEvent::dispatch($this->model); } else { throw new AppCommonException("送信済みエラー"); } } public function canSend() { return $this->canSend; } }