gpt4 book ai didi

php - Laravel 自定义邮件通知表

转载 作者:行者123 更新时间:2023-12-03 22:15:28 24 4
gpt4 key购买 nike

我正在使用 laravel 通知发送电子邮件,但我想知道如何在文本行之间的电子邮件 View 中显示表格。

我正在使用 laravel 的默认 View ,但我不知道如何传递表格'

这是我的 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;
}

在 email.blade.php View (默认 laravel View )中,我有:
{{-- 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

如何放置 Markdown 表,以及如何在行之间放置它,例如操作按钮?

最佳答案

如果 $this->order是一个公共(public)属性,它将在 View 文件中可用。

View Data

Typically, you will want to pass some data to your view that you can utilize when rendering the email's HTML. There are two ways you may make data available to your view. First, any public property defined on your mailable class will automatically be made available to the view. So, for example, you may pass data into your mailable class' constructor and set that data to public properties defined on the class:



否则使用 with将数据传递给 View 的方法。

If you would like to customize the format of your email's data before it is sent to the template, you may manually pass your data to the view via the withmethod. Typically, you will still pass data via the mailable class' constructor; however, you should set this data to protected or private properties so the data is not automatically made available to the template. Then, when calling the with method, pass an array of data that you wish to make available to the template



接下来添加表格组件并循环创建行的订单项:
@component('mail::table')
| id | name | price | qty | subtotal |
| -- |:----:| -----:| ---:| --------:|
@foreach($order->cart as $item)
// create table rows
@endforeach
@endcomponent

关于php - Laravel 自定义邮件通知表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51220419/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com