我有一个控制器,该控制器调用Mail类,该类获取要发送到电子邮件的视图。我能够成功检索单个视图。但是,如何将多个视图合并在一起?
我的控制器:
namespace App\Http\Controllers;
class TestController extends Controller
{
public function sendMail(){
$notification = new NotificationService();
$notification->sendMail();
}
}
服务:
namespace App\Services;
use App\Mail\Test;
use Illuminate\Support\Facades\Mail;
class NotificationService
{
public function sendMail(){
Mail::to(['test@email.com'])->send(new Test);
}
}
邮件:
namespace App\Mail;
use Illuminate\Mail\Mailable;
class Test extends Mailable
{
public function build()
{
$view = $this->getTestView();
return $view;
}
private function getTestView(){
return $this->view(['TestEmail']);
}
}
我需要能够在Mail Test Class中将多个视图放在一起:
EG:
namespace App\Mail;
use Illuminate\Mail\Mailable;
class Test extends Mailable
{
public function build()
{
$view = $this->getTestView();
$view2 = $this->getTestView2()
return $view . $view2;
}
private function getTestView(){
return $this->view(['TestEmail']);
}
// HOW DO I CALL THIS IN THE build()?
private function getTestView2(){
return $this->view(['TestEmail2']);
}
}
答案 0 :(得分:0)
只需创建一个包含两者的新视图
FullEmail.blade.php
@include('TestEmail')
@include('TestEmail2')