Level 39
$emails not initialized
before
Mail::to($email)->send(new WelcomeMail($data))
When i register a new user
protected function create(array $data)
{
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'username' => $data['username'],
'password' => Hash::make($data['password']),
]);
$userRole = Role::select('id')->where('name', 'user')->first();
$user->roles()->attach($userRole);
$email = $data['email'];
$data = ([
'name' => $data['name'],
'email' => $data['email'],
'username' => $data['username'],
]);
Mail::to($email)->send(new WelcomeMail($data));
return redirect('/login')->with('message', 'Account created successfully, Congratulations');
}
public function __construct($data)
{
$this->data = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$subject = 'Welcome';
return $this->view('emails.welcome')->subject($subject);
}
i had to switch to smtp in my .evn and it worked. Thanks!
Please or to participate in this conversation.