参数 1 传递给 App\Mail\OrderPlaced::__construct()
Argument 1 passed to App\Mail\OrderPlaced::__construct()
我想在 placed.plade.php balde 中显示订单信息,但它给我错误:第 77 行的 Argument 1 passed to App\Mail\OrderPlaced::__construct() must be an instance of App\Mail\ App\Order, null given, called in D:\wamp\www\aswakt\routes\web.php
即使我在模型构造函数中传递了一个参数 OrderPlaced.php.
web.php
Route::get('/mailable', function(){
$order = App\Order::find(1);
return new App\Mail\OrderPlaced($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 App\Mail\OrderPlaced($order);
传递的参数 $order
为空。这是因为在您的 orders
table.
中找不到 id = 1
的订单
我想在 placed.plade.php balde 中显示订单信息,但它给我错误:第 77 行的 Argument 1 passed to App\Mail\OrderPlaced::__construct() must be an instance of App\Mail\ App\Order, null given, called in D:\wamp\www\aswakt\routes\web.php
即使我在模型构造函数中传递了一个参数 OrderPlaced.php.
web.php
Route::get('/mailable', function(){
$order = App\Order::find(1);
return new App\Mail\OrderPlaced($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 App\Mail\OrderPlaced($order);
传递的参数 $order
为空。这是因为在您的 orders
table.
id = 1
的订单