我正在使用 Laravel 通知发送电子邮件,但我想知道如何在文本行之间的电子邮件视图中显示表格。
我正在使用 laravel 的默认视图,但我不知道如何传递表'
这是我的 toMail 方法:
public function toMail($notifiable)
{
$message = new MailMessage();
$message->subject('Command confirmation n°'.$this->order->id)
->replyTo('noreply@example.com')
->line('Thanks to choose us!')
->line('Here the details of your order n°'.$this->order->id);
foreach($this->order->cart as $item){
// here the table
}
$message->line('To see your order click here');
$message->action('My orders', url('http://www.example.com/espace-perso/mes-commandes'))
return $message;
}
Run Code Online (Sandbox Code Playgroud)
在 email.blade.php 视图(默认 Laravel 视图)中,我有:
{{-- Action Button --}}
@isset($actionText)
<?php
switch ($level) {
case 'success':
$color = 'green';
break;
case 'error':
$color = 'red';
break;
default:
$color = 'blue';
}
?>
@component('mail::button', ['url' => $actionUrl, 'color' => $color])
{{ $actionText }}
@endcomponent
@endisset
{{-- Outro Lines --}}
@foreach ($outroLines as $line)
{{ $line }}
@endforeach
Run Code Online (Sandbox Code Playgroud)
如何放置降价表,以及如何将其放在行之间,例如操作按钮?
如果$this->order是公共属性,它将在视图文件中可用。
通常,您需要将一些数据传递到您的视图中,您可以在呈现电子邮件的 HTML 时使用这些数据。您可以通过两种方式将数据提供给您的视图。首先,在可邮寄类上定义的任何公共属性都将自动提供给视图。因此,例如,您可以将数据传递到可邮寄类的构造函数中,并将该数据设置为在类上定义的公共属性:
否则使用该with方法将数据传递给视图。
如果您想在发送到模板之前自定义电子邮件数据的格式,您可以通过 with 方法手动将数据传递到视图。通常,您仍将通过可邮寄类的构造函数传递数据;但是,您应该将此数据设置为受保护或私有属性,以便模板不会自动使用这些数据。然后,在调用 with 方法时,传递您希望提供给模板的数据数组
接下来添加 table 组件并循环创建行的订单项:
@component('mail::table')
| id | name | price | qty | subtotal |
| -- |:----:| -----:| ---:| --------:|
@foreach($order->cart as $item)
// create table rows
@endforeach
@endcomponent
Run Code Online (Sandbox Code Playgroud)