__email = $email; Mail::to($email) ->send($this); } public function setUser(User $user) { $this->__userId = $user->id; $this->__email = $user->email; return $this; } public function setEmail(string $target) { $this->__email = $target; return $this; } public function setUserId(string $userId) { $this->__userId = $userId; return $this; } public function setContractId(string $contractId) { $this->__contractId = $contractId; return $this; } public function setReceiptIssuingOrderId(string $receiptIssuingOrderId) { $this->__receiptIssuingOrderId = $receiptIssuingOrderId; return $this; } public function build() { return $this->text($this->getTemplateName()) ->subject($this->getSubject()) ->with($this->getParams()); } public function setConfigDefault() { $root = $this->configRoot; config([ $root . "transport" => "smtp", $root . "host" => env('MAIL_HOST', 'smtp.mailgun.org'), $root . 'port' => env('MAIL_PORT', 587), $root . 'encryption' => env('MAIL_ENCRYPTION', 'tls'), $root . 'username' => env('MAIL_USERNAME'), $root . 'password' => env('MAIL_PASSWORD'), $root . 'timeout' => null, $root . 'auth_mode' => null, $root . 'verify_peer' => false, ]); } public function setConfig(array $config) { $root = $this->configRoot; $ret = []; foreach ($config as $key => $val) { $ret[$root . $key] = $val; } config($ret); } protected function setValues(\stdClass|array $data) { foreach ($data as $key => $val) { $this->setValue($key, $val); } } protected function setValue(string $key, $value) { $val = $value; $camel = Str::camel($key); $snake = Str::snake($key); $property = ""; if (property_exists($this, $camel)) { $property = $camel; } else if (property_exists($this, $snake)) { $property = $snake; } else { return; } if (data_get($this->casts, $property) === 'datetime') { $this->$property = DateUtil::parse($val); } else { $this->$property = $val; } } public function makeModel(): Email { if ($this->__email === "") { throw new AppCommonException("Email宛先不明"); } $model = new Email(); $model->subject = $this->getSubject(); $model->content = $this->render(); $model->type = get_class($this); $model->email = $this->__email; $model->contract_id = $this->__contractId; $model->user_id = $this->__userId; $model->receipt_issuing_order_id = $this->__receiptIssuingOrderId; return $model; } abstract public function getTemplateName(): string; abstract public function getSubject(): string; abstract public function getParams(): array; /** * 画面のURLを生成する * * @param array|string $path * @return string */ protected function getAppUrl(array|string $path): string { $elements = [config("app.url")]; if (is_array($path)) { $elements = array_merge($elements, $path); } else { $elements[] = $path; } return implode( "/", $elements, ); } }