*/ abstract protected function variables(): array; public function envelope(): Envelope { return $this->templateEnvelope($this->rendered()['subject'], $this->template()->mailConfig()); } public function content(): Content { return new Content(htmlString: $this->rendered()['html']); } public function buildViewData() { return [...parent::buildViewData(), AutoEmailGate::SCENARIO_DATA_KEY => $this->scenario()]; } /** * @return array{subject: string, html: string} */ private function rendered(): array { return $this->rendered ??= app(EmailTemplateRenderer::class)->render( $this->template(), [...MailGlobals::values(), ...$this->variables()], ); } private function template(): Template { return app(EmailTemplateService::class)->loadTemplate($this->scenario()); } }