Php Laravel自定义电子邮件通知表
我正在使用laravel通知发送电子邮件,但我想知道如何在文本行之间的电子邮件视图中显示表格 我使用的是来自laravel的默认视图,但我不知道如何传递表的 以下是我的toMail方法:Php Laravel自定义电子邮件通知表,php,laravel,Php,Laravel,我正在使用laravel通知发送电子邮件,但我想知道如何在文本行之间的电子邮件视图中显示表格 我使用的是来自laravel的默认视图,但我不知道如何传递表的 以下是我的toMail方法: public function toMail($notifiable) { $message = new MailMessage(); $message->subject('Command confirmation n°'.$this->order->i
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;
}
在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
{{--操作按钮--}
@isset($actionText)
@组件('mail::button',['url'=>$actionUrl,'color'=>$color])
{{$actionText}}
@端部元件
@尾端集
{{--Outro行--}
@foreach($outroLines作为$line)
{{$line}
@endforeach
如何放置降价表,以及如何在行与行之间放置它,如操作按钮?如果
$this->order
是公共属性,它将在视图文件中可用
通常,您希望将一些数据传递到视图,以便在呈现电子邮件的HTML时使用。有两种方法可以使数据对视图可用。首先,在mailable类上定义的任何公共属性都将自动提供给视图。因此,例如,您可以将数据传递到mailable类的构造函数中,并将该数据设置为类上定义的公共属性:
否则,使用with
方法将数据传递给视图
如果要在电子邮件发送到模板之前自定义其数据格式,可以通过withmethod手动将数据传递到视图。通常,您仍将通过mailable类的构造函数传递数据;但是,应将此数据设置为受保护属性或专用属性,以便该数据不会自动提供给模板。然后,在调用with方法时,传递希望使模板可用的数据数组
接下来,添加表组件并循环创建行的订单项:
@component('mail::table')
| id | name | price | qty | subtotal |
| -- |:----:| -----:| ---:| --------:|
@foreach($order->cart as $item)
// create table rows
@endforeach
@endcomponent