Jump to content

Laravel where do you pass data when sending markdown emails?

Joveice
Go to solution Solved by nuc,
4 hours ago, Joveice said:

How do I pass it with this? I tried to pass it with VerifyEmail($data) but the IDE is complaining about it so I didn't do more testing on it


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

 

Via the constructor of VerifyEmail.

Please consult the docs for w/e framework/lib you're using https://laravel.com/docs/5.6/mail

Hello,

 

I'm creating a mail to make the user verify the email after registration.

 

in RegisterController

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

then in VerifyEmail

public function build()
{
	return $this->markdown('emails.verify-email');
}

Then how do I fill this in the blade?

@component('mail::message')
# Please verify your email

Hello {{ $username }},
You will need to verify your email before you can login.

[{{ route('account.security.verifyEmail', $verification_code) }}]({{ route('account.security.verifyEmail', $verification_code) }})

Thanks,<br>
{{ config('app.name') }}
@endcomponent

I do not understand how I get the data from the register controller to the blade so it's filled when sendt. I managed to view it like this

Route::get('mail', function () {
        $markdown = new Markdown(view(), config('mail.markdown'));
        return $markdown->render('emails.verify-email', [
            'username' => 'test',
            'verification_code' => '12y72179y9y7122189y7'
        ]);
    });

So when the user is registered I have $username and $verification_code which needs to be passed so they can be sendt in the email.

 

Can someone explain? I see that I could do this (at least I got no errors from the IDE)

public function build()
    {
        return $this->markdown('emails.verify-email')
            ->with('username', $username);
    }

But as stated, I have no clue how I get the data there.

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

You answered your own question. Mailable is a component, so the with function is available. Both are correct.

->with('key', $var)

->with('key', [$var])
Link to comment
Share on other sites

Link to post
Share on other sites

7 hours ago, nuc said:

You answered your own question. Mailable is a component, so the with function is available. Both are correct.


->with('key', $var)

->with('key', [$var])
Quote

I do not understand how I get the data from the register controller to the blade so it's filled when sendt.

How do I pass it with this? I tried to pass it with VerifyEmail($data) but the IDE is complaining about it so I didn't do more testing on it

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

 

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

4 hours ago, Joveice said:

How do I pass it with this? I tried to pass it with VerifyEmail($data) but the IDE is complaining about it so I didn't do more testing on it


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

 

Via the constructor of VerifyEmail.

Please consult the docs for w/e framework/lib you're using https://laravel.com/docs/5.6/mail

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, nuc said:

Via the constructor of VerifyEmail.

Please consult the docs for w/e framework/lib you're using https://laravel.com/docs/5.6/mail

Oh, thats how.. Thanks!

Didn't think it was the same for this too, thought it was used in another way :P

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×