1
votes

WelcomeMail.php;

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

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('email.register-mail');
    }
}

RegisterController.php;

protected function create(array $data)
    {
        $user =User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),

        ]);



        $body = [];
        $mailData = array('body'=>$body);

        Mail::send('email.register-mail',$mailData, function ($message) use ($user){
            $message->from(env('MAIL_USERNAME'), 'EksikParça.');
            $message->subject('Hosgeldiniz!');
            $message->to(new WelcomeMail($user));
        });



        return $user;
    }
}

This is the code I wrote for the e-mail I send when the user registers. But I am getting an illegal offset type error. could be caused by why?

1
you should provide the full exact error and the view being usedlagbox
also i don't think you are using that $message->to(...) correctly .. its like you are trying to mix the old style of sending mail and the new mailable togetherlagbox

1 Answers

0
votes

The to() method in the Mail expects the recipient.

You can either pass a user object to it or an email address.

So try doing this instead:

Mail::to($user)
    ->send(new WelcomeMail($user));

You can define the subject and from right in the Mail class. Read more on that here: https://laravel.com/docs/8.x/mail#sending-mail