我想使用laravel-dompdf在邮件上发送pdf而不保存在服务器上
我有下一个代码:
$pdf = PDF::loadView('admin.costs.pdf',array('costscategories' => $costscategories,'marketcosts' => $marketcosts,'bonuscosts' => $bonuscosts));
Mail::send('admin.costs.test', $pdf, function($message)
{
$message->to('test@test.test', 'Jon Doe')->subject('Welcome!');
$message->attachData($pdf, 'invoice.pdf');
});
}
但我得到了下一个错误:
Type error: Argument 2 passed to Illuminate\Mail\Mailer::send() must be of the type array, object given, called in /var/www/html/miltonia-update/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 221
如何解决?
答案 0 :(得分:3)
答案 1 :(得分:1)
如错误所示,您需要将array
传递给Mail::send
函数,但您只是传递$pdf
这是一个对象而不是数组。
这应该有效:
$data = [];
$pdf = PDF::loadView('admin.costs.pdf',array('costscategories' => $costscategories,'marketcosts' => $marketcosts,'bonuscosts' => $bonuscosts));
$data['pdf'] = $pdf;
Mail::send('admin.costs.test', $data, function($message)
{
$message->to('test@test.test', 'Jon Doe')->subject('Welcome!');
$message->attachData($data['pdf'], 'invoice.pdf');
});
}
答案 2 :(得分:0)
谢谢大家!我用下面的想法解决了这个问题:
$pdf = PDF::loadView('admin.costs.pdf',array('costscategories' => $costscategories,'marketcosts' => $marketcosts,'bonuscosts' => $bonuscosts))->stream();
Mail::send('admin.costs.test', ['pdf'=>$pdf], function($message) use ($pdf)
{
$message->to('test@test.test', 'Jon Doe')->subject('Welcome!');
$message->attachData($pdf, 'invoice.pdf');
});