Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: Pass an array from controller, to mail::to

In my project after someone fill a pricequote I want to send an email for him/her. In the controller I made an array what I want to pass to the mailable, to show on the email.

Where I'm now:

$params = array(
        'name' => $name, //user's data
        'email' => $email,
        'phone' => $phone,
        'data' => $data, //other stuffs in the form 
);

Mail::to($email)
    ->send(new pricequote($params));

And after that how to pass from the mailable class to the template?

like image 601
Feralheart Avatar asked Sep 02 '25 02:09

Feralheart


1 Answers

You can use;

namespace App\Mail;

public function __construct($data)
{
    $this->data = $data;
}

public function build()
{
    return $this->view('emails.contacts')
        ->with(['data' => $this->data]);
}
like image 155
syntaxe Avatar answered Sep 05 '25 04:09

syntaxe