我想在placed.plade.php代码中显示订单信息,但它在第77行给了我错误:Argument 1 passed to AppMailOrderPlaced::__construct() must be an instance of AppMail AppOrder, null given, called in D:wampwwwaswaktroutesweb.php
甚至我在模型构造函数orderplace .php中传递了一个参数。
web.php
Route::get('/mailable', function(){
$order = AppOrder::find(1);
return new AppMailOrderPlaced($order);
});
OrderPlaced.php
public $order;
public function __construct(Order $order)
{
$this->order = $order;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->to($this->order->billing_email,$this->order->billing_name)
->bcc('another@another.com')
->subject('Order for aswak tinghir ')
->markdown('emails.orders.placed');
}
placed.blade.php
**Order ID:** {{ $order->id }}
**Order Email:** {{ $order->billing_email }}
**Order Name:** {{ $order->billing_name }}
**Order Total:** ${{ round($order->billing_total / 100, 2) }}
出现错误是因为您在return new AppMailOrderPlaced($order);
传递的参数$order
为空。这是因为在orders
表中没有找到id = 1
的顺序。