Reputation: 2331
I am using MailMessage
to send a mail message to mailtrap, and I pass a variable email
.
My problem it doesn't recognize the variable that I pass in the markdown. It returns an error below
Facade\Ignition\Exceptions\ViewException: Undefined variable: email (View: /var/www/resources/views/ema...
Someone knows what is the proper way of passing and getting the variable from-to markdown?
Here is my code
return (new MailMessage)
->greeting('hello')
->line('Innerline sample')
->action('Reset Button', 'http://localhost:3002/reset?sample=gibor213kg')
->line('sample')
->markdown('emails.reset')
->with('email', '[email protected]');
Here is my markdown look alike
@component('mail::layout', ['email' => $emaill])
//more codes here
{{ $email }}
//more codes here
@endcomponent
Upvotes: 0
Views: 2908
Reputation: 2331
I eventually got the solution, by using the compact
, instead of an array. I changed this line below, and everything works normal.
->markdown('emails.reset', compact('email'))
credits to @sibongisenimsomis from laracasts
Apparently passing variables to Markdown from Notification class works, differently. I used compact on my solution, after struggle for about an hour cause I was referring to another example which was using with, on a Mailable class.
Upvotes: 0
Reputation: 168
Pass the variable as a second parameter.
return (new MailMessage)
->greeting('hello')
->line('Innerline sample')
->action('Reset Button', 'http://localhost:3002/reset?sample=gibor213kg')
->line('sample')
->markdown('emails.reset', [
'email' => '[email protected]',
]);
https://laravel.com/docs/8.x/mail#markdown-mailables
Upvotes: 2