rap*_*2-h 5 php laravel laravel-5 laravel-5.5
根据文档,使用Laravel,我可以Mailable通过控制器返回a ,以在浏览器中显示它。它有助于预览邮件。
有没有办法在浏览器中预览邮件通知?
我试过了:
return (new MyNotification())->toMail($some_user);
Run Code Online (Sandbox Code Playgroud)
但这不起作用:
响应内容必须是实现__toString()的字符串或对象,即“ object”。
在控制器的功能中:
$message = (new \App\Notifications\MyNotification())->toMail('example@gmail.com');
$markdown = new \Illuminate\Mail\Markdown(view(), config('mail.markdown'));
return $markdown->render('vendor.notifications.email', $message->data());
Run Code Online (Sandbox Code Playgroud)
只需更改通知类的名称(并在必要时传递参数),然后在浏览器中单击URL即可预览。
您无法呈现Notification。可以渲染可邮寄您在使用toMail()。例如,如果该 Mailable 被调用SomeMailable:
public function toMail($user)
{
return (new SomeMailable($user))->to($user->email);
}
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用以下命令渲染 Mailable:
return new SomeMailable($some_user);
Run Code Online (Sandbox Code Playgroud)
小智 5
在 Laravel 5.8 中,您现在可以像预览 Mailable 一样预览它。
Route::get('mail-preview', function () {
return (new MyNotification())->toMail($some_user);
});
Run Code Online (Sandbox Code Playgroud)
更多细节在这里:https : //sampo.co.uk/blog/previewing-mail-notifications-in-laravel-just-got-easier
| 归档时间: |
|
| 查看次数: |
1189 次 |
| 最近记录: |