【发布时间】:2019-10-02 22:59:42
【问题描述】:
如何发送可邮寄的集合并在视图中组织我在对象内的集合中创建的项目?
在我的控制器中,我正在创建这样的订单:
$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');
}
在视图中,我收到了数据,但我不知道如何访问每一个
@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
得到这个错误:
试图获取非对象的属性“项目”(查看:/app/resources/views/newpurch.blade.php)
如果我试试这个:
@component('mail::message')
<?php
$deco = json_decode($pro,true);
?>
Someone want this:
{{ $deco }}
@endcomponent
得到这个错误:
htmlspecialchars() 期望参数 1 是字符串,给定数组(查看:/app/resources/views/newpurch.blade.php)
【问题讨论】: