I am trying to send e-mail with Laravel, but I need to send the customer information and the randomly generated password when sending mail.Customer information appears in the outgoing mail, but the password is empty.
Controller function
public function register(RegisterRequest $request)
{
$random = str_shuffle('abcçdefgğhıijklmnoöpqrsştuüvwxyzABCÇDEFGĞHIİJKLMNOÖPQRSŞTUÜVWXYZ234567890!$%^&!$%^&');
$password = substr($random, 0, 10);
$hashed_password = Hash::make($password);
$activation_key = Str::random(60);
$request->request->add(["password"=> $hashed_password,"activation_key"=> $activation_key]);
$customer = Customer::create($request->all());
if ($customer) {
Mail::to(request('email'))->send(new CustomerRegisterMail($customer, $password));
Alert::success('Success', 'Some Success Message');
return back();
} else {
Alert::error('Error', 'Some Error Message');
return back();
}
}
CustomerRegisterMail.php
class CustomerRegisterMail extends Mailable
{
use Queueable, SerializesModels;
public $customer;
public $password;
public function __construct(Customer $customer, $password)
{
$this->customer = $customer;
$this->password = $password;
}
public function build()
{
return $this
->from('[email protected]','Some Name')
->subject(config('app.name'). ' - Customer Register')
->view('mails.customer_register')->with(['name' => $this->customer->name, 'surname' => $this->customer->surname, 'email' => $this->customer->email, 'password' => $this->password]);
}
}
customer_register.blade.php
Hello {{$name}} {{$surname}},
E-Mail : {{$email}}<br>
Password: {{$password}}
And what i get
Hello Behçet Atalay,
E-Mail: [email protected]
Password:
How can I send two variables to mail view at the same time?