作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我如何发送带有 mailable 的集合并在 View 中组织我在对象内的集合中创建的项目?
在我的 Controller 中,我正在创建这样的订单:
$order = Order::create([
'products' => json_encode(new CartItemCollection($items)),
'price' => $PartialPrice,
//other stuff
]);
在我的购买功能中,我发送这样的电子邮件:
$pro = $order->products;
$data = [
'extra_address' => $order->extra_address,
'address' => $order->address,
];
Mail::to($check_user->email)->send(new NewPurch($data, $pro));
在我的电子邮件配置中,我有这个:
public $data;
public $pro;
public function __construct($data,$pro)
{
$this->data = $data;
$this->pro = $pro;
}
public function build()
{
return $this->markdown('newpurch')->with(['data' => $this->data])->subject('Thank you');
}
在 View 中,我收到了数据,但我不知道如何访问每个数据
@component('mail::message')
Someone want this:
{{$pro}}
@endcomponent
但我不能作为对象 $pro->id
或作为键 $pro['id']
访问
编辑:如果我尝试这样做:
@component('mail::message')
Someone want this:
@foreach($pro->items as $item)
{{ $item->id }}
@endforeach
@endcomponent
得到这个错误:
Trying to get property 'items' of non-object (View: /app/resources/views/newpurch.blade.php)
如果我尝试这样做:
@component('mail::message')
<?php
$deco = json_decode($pro,true);
?>
Someone want this:
{{ $deco }}
@endcomponent
得到这个错误:
htmlspecialchars() expects parameter 1 to be string, array given (View: /app/resources/views/newpurch.blade.php)
最佳答案
编辑:
public $data;
public $pro;
public function __construct($data, $pro)
{
$this->data = $data;
$this->pro = json_decode($pro, true);
}
public function build()
{
return $this->markdown('newpurch')->with(['data' => $this->data])->subject('Thank you');
}
并使用 foreach,因为我们现在回到集合而不是字符串。
@foreach($pro->items as $item)
{{ $item->id }}
@endforeach
关于php - 如何将集合传递给可邮寄的 laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58210351/
我是一名优秀的程序员,十分优秀!