Home > Net >  Argument 1 passed to App\Mail\OrderPlaced::__construct()
Argument 1 passed to App\Mail\OrderPlaced::__construct()

Time:10-25

I want to display the information of an order in a placed.plade.php balde but it gives me error: 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 on line 77 even I pass an argument in the model constructor 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('[email protected]')
                    ->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) }}

CodePudding user response:

The error comes because the parameter $order you are passing at return new App\Mail\OrderPlaced($order); is null. This comes because there is no order with id = 1 found in your orders table.

  • Related