I have seached and found so many solutions of this and tried all but the issue is same.
class InvoiceMail extends Mailable
{
use Queueable, SerializesModels;
public $user;
public $payment;
public $invN;
public function __construct($user,$payment,$invNum)
{
//
$this->user = $user;
$this->payment = $paymentt->toArray();
$this->invN = $invNum;
}
public function build()
{
$user = $this->user;
return $this->from('hardliftersgym@gmail.com')->view('email.invoice')->with(['user'=>$user])->attach('invoice/'.$this->invN);
}
}
I have tried this
public function build()
{
$data = array('user'=>$this->user);
return $this->from('hardliftersgym@gmail.com')->view('invoice',$data)->attach('invoice/'.$this->invN);
}
and this is also not working
return $this->from('hardliftersgym@gmail.com')->view('invoice')->with('user',$this->user)->attach('invoice/'.$this->invN);
and
return $this->from('hardliftersgym@gmail.com')->view('invoice',compact('user'))->attach('invoice/'.$this->invN);
and these are also caught the same error
Undefined variable: user (View: resources/views/email/invoice.blade.php)
I am trying to resolve this since morning but I am not getting what is wrong with the code.
Please help.