I want to send the data of the last order just made by the user
I already have my .env configured
AfterOrder Class: (Class type mail)
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use App\Models\Order;
class AfterOrder extends Mailable
{
use Queueable, SerializesModels;
public $order;
public function __construct(Order $order)
{
$this->Order = $order;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('mail.after-order');
}
}
View:
<div class="container">
<h1>Name: {{$order->user->name}}</h1>
</div>
the user table is a belongsto of orders
Controller:
public function sendMail(Order $order) {
$order = $order->newQuery();
$order->whereHas('user', function($query){
$query->where('email', '=', \Auth::user()->email);
});
$order->orderBy('id', 'desc')->first();
$user = User::where('email', '=', \Auth::user()->email)->first();
Mail::to($user->email)->send(new AfterOrder($order));
//return redirect()->route('home')->with(['message' => 'Thank you for shopping at Sneakers!']);
}
Whats wrong? i got this error

$this->Orderin the AfterOrder constructor?