Skip to content
Advertisement

How to pass variable to markdown? laravel mail

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

FacadeIgnitionExceptionsViewException: 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', 'orange@gmail.com');

Here is my markdown look alike

@component('mail::layout', ['email' => $emaill])

//more codes here

{{ $email }}

//more codes here

@endcomponent

Advertisement

Answer

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.

https://laracasts.com/discuss/channels/laravel/passe-some-variables-to-the-markdown-template-within-a-notification

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement